Numerical representation

Jon Herman jfc.herman at gmail.com
Mon Mar 7 13:36:11 EST 2011


I'm starting to run out of ideas of what to do...I've imported the true
division (I'm using Python 2.7) to make sure I wasn't accidentally using any
integers but the results remain identical, so it's not a division problem.
I've copied the loop I'm running below, is there any mathematical operation
I am making here that may have an accuracy problem? Thanks for any advice
you can give!

        Xold=X
        told=t

        if abs(dt) > abs(tf-t):
            dt = tf-t

        k[:,0]=F(mu, Xold, told)

        for n in range(1,13):
            nn=n-1
            Xtemp1=zeros(neq)
            for j in range(nn):
                Xtemp1 = Xtemp1 + b[n,j] * k[:,j]
            Xtemp1
            X=Xold+ dt * Xtemp1
            t=told+a[n]*dt
            k[:,n]=F(mu, X, 0)

        Xtemp2=zeros(neq)
        for l in range(13):
            Xtemp2=Xtemp2+c[l]*k[:,l]



        X=Xold + dt * Xtemp2
        t=told+dt

        Xstore=vstack((Xstore,X))
        tstore=vstack((tstore,t))

        if abs(tf-t)< 1e-14:
            print('At tf')
            break




On Fri, Mar 4, 2011 at 6:46 PM, Jon Herman <jfc.herman at gmail.com> wrote:

> Actually, I import numpy in my code for array creation...in the
> documentation I did not manage to find anything that would solve this
> precision problem I mentioned however. If you're familiar with it, would you
> happen to know what capability of numpy might solve my problem?
>
>
>
>
> On Fri, Mar 4, 2011 at 4:49 PM, Santoso Wijaya <santoso.wijaya at gmail.com>wrote:
>
>> Have you taken a look at numpy? [1] It was written for exactly this kind
>> of usage.
>>
>> ~/santa
>>
>> [1] http://numpy.scipy.org/
>>
>>
>> On Fri, Mar 4, 2011 at 2:32 PM, Jon Herman <jfc.herman at gmail.com> wrote:
>>
>>> Hello all,
>>>
>>> I am new to the Python language and writing a Runge-Kutta-Fellberg 7(8)
>>> integrator in Python, which requires an extreme numerical precision for my
>>> particular application. Unfortunately, I can not seem to attain it.
>>> The interesting part is if I take my exact code and translate it to
>>> Matlab code (so I use the exact same process and numbers), I get a far
>>> superior precision (the one I am expecting, in fact). This leads me to think
>>> I need to call a certain command in my Python script in order to make sure
>>> no truncation errors are building up over my integration.
>>>
>>> Has anyone had similar problems? Is there a difference between how Matlab
>>> and Python store numbers, and if so how do I make Python more accurate?
>>>
>>> I know there is a lot of packages out there, but this in fact overwhelmed
>>> me a little bit and seems to prevent me from finding the answer to my
>>> question, so I'm hoping someone with more experience will be able to
>>> enlighten me!
>>>
>>> Best regards,
>>>
>>> Jon
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110307/cd949e15/attachment.html>


More information about the Python-list mailing list