Mathematica 7 compares to other languages

Kaz Kylheku kkylheku at gmail.com
Wed Dec 10 16:37:34 EST 2008


On 2008-12-05, Xah Lee <xahlee at gmail.com> wrote:
> Let's say for example, we want to write a function that takes a vector
> (of linear algebra), and return a vector in the same direction but
> with length 1. In linear algebar terminology, the new vector is called
> the “normalized” vector of the original.
>
> For those of you who don't know linear algebra but knows coding, this

If I were to guess who that would be ...

> 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.

Really? ``50 or hundreds'' of lines in C?

  #include <math.h> /* for sqrt */

  void normalize(double *out, double *in)
  {
	double denom = sqrt(in[0] * in[0] + in[1] * in[1] + in[2] * in[2]);

        out[0] = in[0]/denom;
	out[1] = in[1]/denom;
	out[2] = in[2]/denom;
  }

Doh?

Now try writing a device driver for your wireless LAN adapter in Mathematica.



More information about the Python-list mailing list