Permalink
Cannot retrieve contributors at this time
06_initial_value_ode/Prob2ptC.asv
Go to filefunction y=Prob2ptC(ode,dt,y0,tlimits) | |
maxit=100; | |
t=[tlimits(1):dt:tlimits(2)]; | |
y=zeros(length(t),1); | |
y(1)=y0; | |
for i=2:length(t) | |
dy=ode(t(i-1),y(i-1)); | |
y(i)=y(i-1)+dt*dy; | |
dyc=(dy+ode(t(i),y(i)))/2; | |
y(i)=y(i-1)+dt*dyc; | |
nits=1; | |
while(1) | |
nits=nits+1; | |
yold=y(i); | |
dyc=(dy+ode(t(i),y(i)))/2; | |
y(i)=y(i-1)+dt*dyc; | |
ea=abs(yold-y(i))/y(i)*100; | |
if ea<.0001|nits>maxit;break;end; | |
end; | |
end | |
end |