Numerical representation

Jon Herman jfc.herman at gmail.com
Tue Mar 8 15:21:59 EST 2011


Thanks all for the input, the remark about printing intermediate steps was a
very good one (and so obvious I can't believe it took me this long to get
there...)

The error was in my loop where I multiply by the "b" or "beta" coefficients.
The range for this loop (marked by j) is set up properly in Matlab (1 to nn)
but in Python running this over range(nn) drops the values of the column
'nn'. That means the coefficients were all wrong. This quickly became
apparent as I was printing a number of internal values.

Thank you for the assistance, I apologize for asking your time for such a
beginner's oversight...I'll be fluent in Python some day ;-)



On Mon, Mar 7, 2011 at 5:34 PM, Robert Kern <robert.kern at gmail.com> wrote:

> On 3/7/11 2:52 PM, Jon Herman wrote:
>
>> It really is exactly the same process, but sure. Below is my Matlab
>> translation
>> of the python code I posted earlier, it functions at the increased
>> accuracy I've
>> shown above.
>>
>>    k(:,1)=feval(deq, ti, x, mu);
>>
>>      for n = 2:1:13
>>             nn=n-1;
>>             Xtemp1 = 0.0;
>>             for j = 1:1:nn
>>                 Xtemp1 = Xtemp1 + beta(n,j) * k(:,j);
>>             end
>>             x=xwrk+ dt * Xtemp1;
>>             ti=twrk+alph(n)*dt;
>>             k(:,n)=feval(deq, ti, x, mu);
>>      end
>>
>>       Xtemp2=0.0;
>>         for l  = 1:1:13
>>             Xtemp2=Xtemp2+ch(l)*k(:,l);
>>         end
>>
>>
>>         x=xwrk + dt * Xtemp2;
>>         t=twrk+dt;
>>
>
> You may want to try printing out values in both implementations to see
> where they start to diverge.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma
>  that is made terrible by our own mad attempt to interpret it as though it
> had
>  an underlying truth."
>  -- Umberto Eco
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110308/fc99e921/attachment-0001.html>


More information about the Python-list mailing list