Matlab coding explicit midpoint method coding,
Show older comments
%Where i have a separate file lorenz.m which contains
%function [ dx ] = lorenz( t,x ) %sig=10; %beta=8/3 %rho=28; %dx=[-sig*x(1)+sig*x(2); rho*x(1)-x(2)-x(1)*x(3);-beta*x(3)+x(1)*x(2)]; %end
function [ t,x ] = RK2(lorenz,t0,tn,n ) t(1)=t0 x(:,1)=[1 1 1] h=(tn-t0)/n
for k=1:n
d1=lorenz(t(k),x(:,k))
d2=lorenz((t(k)+h/2), x(:,k)+(d1)/2);
x(:,k+1)=x(:,k)+h*d2
end
If I try to solve this in script [t x]=RK2(lorenz,0,100,100000) for t=0 to 100 and h=0.0001 so that n steps are 100000, I keep getting error.... can you guys help???
Answers (0)
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!