
December 4th, 2012, 03:18 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
Time spent in forums: 1 h 2 m 5 sec
Reputation Power: 0
|
|
|
Improving ODE algorithm
Hi, I'm doing python in class and have got completely stuck.
I have this code to solve an ODE, but now I need to improve it so that after finding the slope at a point A, it uses it to find some point B, it's slope, then averages them out to get a better value. Here's the code:
Code:
def f(y,t):
return -y+1.0
def odestep(f,y,t,dt):
return y+dt*f(y,t)
t=0; y=0; dt=0.2
tf=2.0; nsteps=int(tf/dt)
print t, y
for i in range(nsteps):
y=odestep(f,y,t,dt)
t=(i+1)*dt
print t, y
Thanks.
EDIT: solved, nevermind.
|