Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. def quadraticcase(t0,tend,dt,k,fun,teta,x0): #solver for the case of quadratic energy
  2.     #fun is a linear function with time in argument; dt is the change in time
  3.     f=sy.sympify(fun) #converting string into function with t in argument
  4.     n=(tend-t0)/dt #n: number of time steps till tend is reached
  5.     t_tuple=np.linspace(t0,tend,n+1) #time grid
  6.     x_tuple=np.zeros([n+1]) #x-grid
  7.     x_left=np.zeros([n+1])
  8.     x_right=np.zeros([n+1])
  9.     x_left[0]=(f(t[0])-teta)/k
  10.     x_right[0]=(f(t[0])+teta)/k
  11.     for i in range(1,n+2):
  12.         x_left[i]=(f(t[i])-teta)/k
  13.         x_right[i]=(f(t[i])+teta)/k
  14.         if x[i-1]>x_left[i-1] or x[i-1]<x_right[i-1]:
  15.             x[i]=x[i-1]
  16.             elif x[i-1]<=x_left[i-1]:
  17.                 x[i]=x_left
  18.                 else:
  19.                     x[i]=x_right
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement