[Tutor] Problems using odeint
Steven D'Aprano
steve at pearwood.info
Wed Jan 15 01:51:38 CET 2014
On Tue, Jan 14, 2014 at 06:40:03PM +0000, Grace Roberts wrote:
[...]
> I've attached a quick print-screen of the code.
I've managed to have a look at the screenshot, there are no obvious
problems, but I'm not a Scipy expert. If you do get an answer from a
Scipy mailing list, I would really appreciate it if you were to write
back here with an explanation.
In the meantime, I have a couple of comments about your code. You
initialise some constants like this:
G = -6.67*10**-11
Mm = 6.4*10**23
You can write them more compactily as:
G = -6.67e-11
Mm = 6.4e23
Notice that you have made G a negative value? That is unusual, normally
G is quoted as a positive quantity, G = 6.67e-11 m³/(kg*s²), or the same
value with units N (m/kg)². Either way, G is given a positive value.
Possibly making G a negative quantity is causing the problems?
Another minor comment on your code, in the f(x, t) function you have a
line taking a square root:
r = (x[0]**2 + x[2]**2)**0.5
You can improve the accuracy of that radius calculation by using
the hypot function. First, at the top of the file, import
the math module:
import math
Then inside the f(x,t) function change the calculation of r to this:
r = math.hypot(x[0], x[2])
Hope this is helpful,
--
Steven
More information about the Tutor
mailing list