# Issues with numpy.linspace()

The following code:

# Restricted Three Body Problem
# Plotting x,y,dx,dy

# Import
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# Variables
a,x,y,u,v,xdot,ydot,udot,vdot = var('a,x,y,u,v,xdot,ydot,udot,vdot')

# Sun-Jupiter Ratio
Em = 317.83
Ms = 5.9736*10^24
Sm = Em/Ms
b = Sm/(1+Sm)

# Restricted Three Body Problem
def r3bp(a,x,y,t):
a = b
x = x
y = y
u = u
v = v
xdot = u
ydot = v
udot = -(1-a)*((x-a)/(sqrt((x-a)^2 + y^2))^3)-a*((x+1-a)/(sqrt((x+1-a)^2 + y^2))^3)+x+2*v
vdot = -(1-a)*(y/(sqrt((x-a)^2 + y^2))^3)-a*(y/(sqrt((x+1-a)^2 + y^2))^3)+y-2*u
return[xdot,ydot,udot,vdot]

# Initial conditions
x0 = -0.509
y0 = 0.883
u0 = 0.0259
v0 = 0.0149
t = np.linspace(0,100,num=1000)
x,y,u,v = odeint(r3bp,x0,y0,u0,v0,t)

# Data
x = x[:,0]
y = y[:,0]
u = u[:,0]
v = v[:,0]

# Plot functions
px = plt.plot(t,x)
py = plt.plot(t,y)
pu = plt.plot(t,u)
pv = plt.plot(t,v)
plot.show(px)
plot.show(py)
plot.show(pu)
plot.show(pv)


produces the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-2a6a37bd25e9> in <module>()
34 u0 = RealNumber('0.0259')
35 v0 = RealNumber('0.0149')
---> 36 t = np.linspace(Integer(0),Integer(100),num=Integer(1000))
37 x,y,u,v = odeint(r3bp,x0,y0,u0,v0,t)
38

/opt/sagemath-9.0/local/lib/python3.7/site-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
136     stop  = asanyarray(stop)  * 1.0
137
--> 138     dt = result_type(start, stop, float(num))
139     if dtype is None:
140         dtype = dt

TypeError: data type not understood

edit retag close merge delete

Hi nooniensoong97

you should use the code button (the one marked 101. I think there is a lot of syntax errors in your code.

have a look at this post : coupled second order differential equation

The way the code appeared while the code portions of the question were not properly formatted as code, the asterisks for multiplication (*) were interpreted as markdown for "italics" and thus not displayed, which could give the impression of syntax errors.