Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

I am doing runge kutta order 4 for a system of equations.Any bugs that giving me x1 and x2 =0 for all 200 values?

4 vues (au cours des 30 derniers jours)
function[]= xp(n,t,x,i)
k(1,i+1)=-3*x(2);
k(2,i+1)=(1/3)*x(1); (differential equations)
end
function[]= abc(n,h,t,step)
global x;
x=zeros(3);
disp(0)
disp(t)
disp(x(1))
k=zeros(step-1,4 ) ;
y=zeros(step-1,4 ) ;
for j=1:step
xp(n,t,x,1)
for i=1:n
y(i)=x(i)+(1/2)*h*k(i,1);
end
xp(n,t+h/2,y,2)
for i=1:n
y(i)=x(i)+(1/2)*h*k(i,2);
end
xp(n,t+(h/2),y,3)
for i=1:n
y(i)= x(i)+(1/2)*h*k(i,3);
end
xp(n,t+h,y,k(i,4))
for i=1:n
x(i)=k(i)+(1/6)*h*(k(i,1)+k(i,2)+k(i,3)+k(i,4));
end
t=t+h;
disp(j)
disp(t)
disp(x(1))
disp(x(2))
end
end
function []=test1()
n=2;
step=100;
a=0;
b=4;
t=0;
x(1)=0; % initial condition
x(2)=1; % initial condition
h=(b-a)/step;
abc(n,h,t,step)
end

Réponses (1)

Abraham Boayue
Abraham Boayue le 10 Avr 2018

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by