# Python, scipy.integrate.solve_ive, a problem with plotting a graph

## Summary:

I want to plot v vs t, but the code doesn't return enough points for plotting
Hi, I have this code that solve the equation of motion of a relativistic electron.
Python:
from math import sqrt
from scipy.integrate import odeint, solve_ivp
import numpy as np
import matplotlib.pyplot as plt

e = 1.602 * 10 ** (-19)
E = 10 ** 6
m = 9.106 * 10 ** (-31)

def d2vdt2(t,r):
t_arr = []
v_arr = []
c = 300000000
e = 1.602*10**(-19)
E = 10**6
m = 9.106*10**(-31)
tau = 6*10**(-24)
v,a = r
gamma = 1/sqrt(1-(v**2)/(c**2))
d2vdt2 = (1/(tau*(gamma)**6))*((e*E/m) - a*((6*tau*v*a*gamma**8)/(c**2) + gamma + (v**2)*(gamma**3)/(c**2)))
print(t,v/c)
return a,d2vdt2

a = solve_ivp(d2vdt2,(0, 20*10**(-9)), (0,e*E/m),"Radau")
The problem is I want to plot v vs t, but I don't know how get lists of v and t from the function. If I have the function return v and t, then the code won't loop enough times to get enough data points for plotting. The results of v and t printed out in the function are correct, but I don't know how to make lists of them as the function resets every time it is called by solve_ivp, and the values of v and t from the previous iteration are gone. Thanks!

Related Programming and Computer Science News on Phys.org
Arman777
Gold Member
Is the graph should be something like this ?

#### Attachments

• 7 KB Views: 44
Is the graph should be something like this ?
That is the acceleration vs time. I need velocity vs time. I already got the solution now. Thanks for replying.

Ibix
Have you read the documentation for the function you are using? A quick search suggests that your returned value a should contain what you are looking for as members called t and y.

Have you read the documentation for the function you are using? A quick search suggests that your returned value a should contain what you are looking for as members called t and y.