Home > other >  MATLAB with fourth order runge kutta method lorentz equations where is the following code wrong?
MATLAB with fourth order runge kutta method lorentz equations where is the following code wrong?

Time:11-09

The function y=rk4 (tspan, y0, nt, n)

Y=zeros (nt, n);
Y (1, :)=y0;
H=(tspan (2) - tspan (1))/nt;

For I=1: nt
T=tspan (1) + (I - 1) * h;
K1=dydt (t, y0, n);
K2=dydt (t + 0.5 * h, y0 + 0.5 * h * k1, n);
K3=dydt (t + 0.5 * h, y0 + 0.5 * h * k2, n);
K4=dydt (t + h, y0 + h. * k3, n);

Y (I + 1, :)=y (I, :) + h/6 x + 2 * (k1, k2 + 2 * k3, k4);
End

End


The function y=dydt (t, y0, n)
% UNTITLED shown here on the function of the
% details is shown here
Sigma=10;
Rho=28;
Beta=8/3;

Y=zeros (1, n);

Y (1)=sigma * (y0 (2) - y0 (1));
(2)=y0 y (1) * (rho - y0 (3)) - y0 (2);
(3)=y0 y (1) * y0 (2) - beta * y0 (3);

end
  • Related