Mathematica 7 compares to other languages
Jon Harrop
jon at ffconsultancy.com
Wed Dec 10 18:02:08 EST 2008
Xah Lee wrote:
> Kaz Kylheku wrote:
>> 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?
>
> Kaz, pay attention:
>
> Xah wrote: «Note, that the “norm” as defined above works for vectors
> of any dimention, i.e. list of any length.»
That is still only 6 lines of C code and not 50 as you claimed:
double il = 0.0;
for (int i=0; i<n; ++i)
il += in[i] * in[i];
il = 1.0 / sqrt(il);
for (int i=0; i<n; ++i)
out[i] = il * in[i];
Try computing the Fourier transform of:
0.007 + 0.01 I, -0.002 - 0.0024 I
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u
More information about the Python-list
mailing list