MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: thanks for the help with list - extended syntax question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40665] Re: thanks for the help with list - extended syntax question
  • From: "Steve Luttrell" <luttrell at _removemefirst_westmal.demon.co.uk>
  • Date: Sat, 12 Apr 2003 03:12:55 -0400 (EDT)
  • References: <b75mvb$24v$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In Mathematica you can use For to do something rather like what you want to
do, but it is very inefficient. It is much better to use Mathematica's
native list processing abilities. Here is how to do what you want:

Apply[Plus, Apply[Times, data, 1]]

The Apply[Times, data, 1] turns your list into {x1 y1,x2 y2,...,xn yn}, then
the Apply[Plus, ...] turns this into x1 y1+x2 y2+x3 y3.

--
Steve Luttrell
West Malvern, UK

"Nathan Moore" <nmoore at physics.umn.edu> wrote in message
news:b75mvb$24v$1 at smc.vnet.net...
> Why is it in Mathematica that I can't operate on lists as if they are long
> arrays(in the style of c)  It would be orders of magnitude easier or me to
> just type,
>     data = {{x1,y1},{x2,y2}...{xn,yn}}
> and then find the desited sum like,
>     for(i=0,sum=0;i<;i++) { sum += data[[i,1]]*data[[i,2]]; }
>
> It seems idiotic that syntax like this (which most of the scientific world
> would understand) is not allowed!  I hate learning new (redundant)
computer
> languages!!!
>
> Nathan
>
>




  • Prev by Date: Radio Buttons, Check Boxes, etc.
  • Next by Date: Calculating Easter
  • Previous by thread: Re: thanks for the help with list - extended syntax question
  • Next by thread: Re: thanks for the help with list - extended syntax question