Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from scipy.integrate import ode
- Ts = 0.1
- t = np.arange(0, 10, Ts)
- x0 = 0
- y0 = 0
- phi0 = 0
- x = []
- y = []
- phi = []
- x.append(x0)
- y.append(y0)
- phi.append(phi0)
- def fun(t, y):
- return [np.sqrt(1+4*t**2)* np.cos(y[2]), np.sqrt(1+4*t**2)*np.sin(y[2]), 2/(4*t**2+1)]
- r = ode(fun).set_integrator('dopri5')
- r.set_initial_value([x0, y0, phi0])
- for i in t:
- if r.successful():
- r.integrate(r.t + Ts)
- x.append(r.y[0])
- y.append(r.y[1])
- phi.append((r.y[2]) % (2 * np.pi)) #Just to keep phi in range 0 to 2pi
- x = np.array(x)
- y = np.array(y)
- plt.grid()
- plt.plot(x, y)
- plt.annotate("Starting point",(x0,y0))
- plt.scatter(x0,y0)
- plt.xlabel("x")
- plt.ylabel("y")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement