Differential Equation Solving System: Difference between revisions

From GM-RKB
Jump to navigation Jump to search
No edit summary
No edit summary
Line 7: Line 7:
import math
import math
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
# Initial conditions
\# Initial conditions
y0 = 2.0
y0 = 2.0
# Time step and final time
\# Time step and final time
dt = 1.0 # days
dt = 1.0 # days
tf = 364 .0 # days
tf = 364 .0 # days
# Empty lists to hold the time and solution
\# Empty lists to hold the time and solution
tt = [ ]
tt = [ ]
yy = [ ]
yy = [ ]
# Append initial values
\# Append initial values
tt.append (0.0)
tt.append (0.0)
yy . append (y0)
yy . append (y0)
# Parameters of our equation
\# Parameters of our equation
a = 0.01
a = 0.01
omega = 2.0*math.pi/365.0
omega = 2.0*math.pi/365.0
# Iteration
\# Iteration
while tt [−1] <= tf :
while tt [−1] <= tf :
r = a*yy[−1]*(1+math . sin(omega*tt[ − 1 ]))
r = a*yy[−1]*(1+math . sin(omega*tt[ − 1 ]))

Revision as of 12:19, 15 January 2016

A Differential Equation Solving System is an equation solving system that can apply a differential equation solving algorithm to solve a differential equation solving task.

import math import matplotlib.pyplot as plt \# Initial conditions y0 = 2.0 \# Time step and final time dt = 1.0 # days tf = 364 .0 # days \# Empty lists to hold the time and solution tt = [ ] yy = [ ] \# Append initial values tt.append (0.0) yy . append (y0) \# Parameters of our equation a = 0.01 omega = 2.0*math.pi/365.0 \# Iteration while tt [−1] <= tf : r = a*yy[−1]*(1+math . sin(omega*tt[ − 1 ])) yy.append(yy[−1]+ r*dt) tt.append (tt[−1]+dt) plt.figure(1) plt.plot(tt,yy,'.') plt.xlabel('Time[days]') plt.ylabel('Rats[rats]') plt.title('Euler Solution') plt.show( )