<jupyter_start><jupyter_text>EulerHow to use the module<jupyter_code>from Solver.Euler import Euler
import numpy as np

import matplotlib
#matplotlib.use('WebAgg')
#matplotlib.use('Qt4Cairo')
#matplotlib.use('Qt5Cairo')
matplotlib.use('nbAgg')
import matplotlib.pyplot as plt

plt.rcParams['font.family']='serif'
plt.rcParams['font.size']=10
plt.rcParams['mathtext.fontset']='stixsans'
class diff_eq:
    def __init__(self,n=1):
        self.n_eqs=n
        
        
    def __call__(self,y,t):#to avoid passing function as an argument you can just overload the operator "()".
        
        return [-20*y[0]*t**3,
                5*y[0]*t**2+2*(-y[1]**2+y[2]**2)*t,  
                15*y[0]*t**2+2*(y[1]**2-y[2]**2)*t ]

    
dydt=diff_eq(3)

in0=[5,10,0]
sol1=Euler(dydt,in0,50)
sol2=Euler(N=10000,init_cond=in0,diffeq=dydt)

sol1.solve()
sol2.solve()
fig=plt.figure(figsize=(8,4.5))
fig.subplots_adjust(bottom=0.15, left=0.1, top = 0.9, right=0.9,wspace=0.0,hspace=0.5)
fig.suptitle('')


sub = fig.add_subplot(111)
# for i in range(len(sol1.solution)):
#     sub.plot(sol1.steps,sol1.solution[i],linestyle='--',linewidth=3)

for i in range(len(sol2.solution)):
    sub.plot(sol2.steps,sol2.solution[i],linestyle='-')
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup