Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def quadraticcase(t0,tend,dt,k,fun,teta,x0): #solver for the case of quadratic energy
- #fun is a linear function with time in argument; dt is the change in time
- f=sy.sympify(fun) #converting string into function with t in argument
- n=(tend-t0)/dt #n: number of time steps till tend is reached
- t_tuple=np.linspace(t0,tend,n+1) #time grid
- x_tuple=np.zeros([n+1]) #x-grid
- x_left=np.zeros([n+1])
- x_right=np.zeros([n+1])
- x_left[0]=(f(t[0])-teta)/k
- x_right[0]=(f(t[0])+teta)/k
- for i in range(1,n+2):
- x_left[i]=(f(t[i])-teta)/k
- x_right[i]=(f(t[i])+teta)/k
- if x[i-1]>x_left[i-1] or x[i-1]<x_right[i-1]:
- x[i]=x[i-1]
- elif x[i-1]<=x_left[i-1]:
- x[i]=x_left
- else:
- x[i]=x_right
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement