Matlab coding explicit midpoint method coding,

%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???

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Cell Arrays 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by