Mathematica 7 compares to other languages

toby toby at telegraphics.com.au
Thu Dec 11 00:03:10 EST 2008


On Dec 10, 3:37 pm, w_a_x_... at yahoo.com wrote:
> On Dec 5, 9:51 am, Xah Lee <xah... at gmail.com> wrote:
>
>
>
> > For those of you who don't know linear algebra but knows coding, this
> > means, we want a function whose input is a list of 3 elements say
> > {x,y,z}, and output is also a list of 3 elements, say {a,b,c}, with
> > the condition that
>
> > a = x/Sqrt[x^2+y^2+z^2]
> > b = y/Sqrt[x^2+y^2+z^2]
> > c = z/Sqrt[x^2+y^2+z^2]
>
> > In lisp, python, perl, etc, you'll have 10 or so lines. In C or Java,
> > you'll have 50 or hundreds lines.

void normalise(float d[], float v[]){
    float m = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
    d[0] = v[0]/m;  // My guess is Xah Lee
    d[1] = v[1]/m;  // hasn't touched C
    d[2] = v[2]/m;  // for near to an eternitee
}


>
> Ruby:
>
> def norm a
>   s = Math.sqrt(a.map{|x|x*x}.inject{|x,y|x+y})
>   a.map{|x| x/s}
> end




More information about the Python-list mailing list