Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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?

1 回表示 (過去 30 日間)
Muhtasim Ahmed
Muhtasim Ahmed 2018 年 4 月 10 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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

回答 (1 件)

Abraham Boayue
Abraham Boayue 2018 年 4 月 10 日

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by