Re: HELP : Mathematica v4 producing erroneous results ! Mathematica3 worked fine...
- To: mathgroup at smc.vnet.net
- Subject: [mg19098] Re: HELP : Mathematica v4 producing erroneous results ! Mathematica3 worked fine...
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Thu, 5 Aug 1999 01:35:15 -0400
- Organization: University of Western Australia
- References: <7nrebg$icj@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Chris Slinger wrote:
> I have traced the fault, and the code below is distilled down to illustrate the
> problem. Basically, I'm simply assigning complex numbers to an array using a
> Do[] (but note the Fourier[], which seems to be necessary to cause the bug, for
> some reason). Unfortunately, the imaginary parts of the result are not correct
> - their values should be as in the array "ideal" but are simply equal to the
> real parts !!
>
> Can people reproduce it ?
Yes.
> What is going on ?
Don't know. But I think it has nothing to do with Do. E.g.,
In[1]:= SeedRandom[1];
In[2]:= ideal = Table[Random[Complex, {-1 - I, Plus[1] + I}], {2}, {2}]
Out[2]= {{0.337385 + 0.6624 I, 0.563615 - 0.750732 I},
{0.869075 + 0.200504 I, 0.516709 + 0.938178 I}}
In[3]:= output = Fourier[ideal]
Out[3]= {{1.14339 + 0.525175 I, 0.0630679 + 0.337729 I},
{-0.242392 - 0.613507 I, -0.289297 + 1.0754 I}}
In[4]:= output[[1,1]] = ideal[[1,1]]
Out[4]= 0.337385 + 0.6624 I
In[5]:= output[[1,1]]
Out[5]= 0.337385 + 0.337385 I
> No comments please on style or
> content - remember this is a cut down version of a far larger notebook just to
> illustrate the point:
I still cannot resist -- especially if this is a cut down version of a far larger
Notebook! Why not just write
In[6]:= output = ideal
Out[6]= {{0.337385 + 0.6624 I, 0.563615 - 0.750732 I},
{0.869075 + 0.200504 I, 0.516709 + 0.938178 I}}
or, if you only want to overwrite a specific block of a matrix, you can use
In[7]:= output[[Range[2],Range[2]]] = ideal[[Range[2],Range[2]]]
Out[7]= {{0.337385 + 0.6624 I, 0.563615 - 0.750732 I},
{0.869075 + 0.200504 I, 0.516709 + 0.938178 I}}
both of which work and should be more efficient.
____________________________________________________________________
Paul Abbott Phone: +61-8-9380-2734
Department of Physics Fax: +61-8-9380-1014
The University of Western Australia
Nedlands WA 6907 mailto:paul at physics.uwa.edu.au
AUSTRALIA http://physics.uwa.edu.au/~paul
God IS a weakly left-handed dice player
____________________________________________________________________