フィルターのクリア

How to apply runge kutta method for system of equations that are coupled ODE's? like x1'= -3*x2 and x2'=(1/3)*x1? I tried the code below but get an error on function define saying too may input arguments.

1 回表示 (過去 30 日間)
y=zeros(1,length(x));
z=zeros(1,length(x));
y(1)=0;
z(1)=0;
Fx1= @(x2)(3)*x2;
Gx2=@(x1)(1/3)*x1;
for i=2:(length(x)-1)
k1=Fx1(x(i),y(i));
g1=Gx2(x(i),y(i));
k2=Fx1(x(i)+0.5*h,y(i)+0.5*h*k1);
g2=Gx2(x(i)+0.5*h,y(i)+0.5*h*g1);
k3=Fx1((x(i)+0.5*h),(y(i)+0.5*h*k2));
g3=Gx2((x(i)+0.5*h),(y(i)+0.5*h*g2));
k4=Fx1((x(i)+h),(y(i)+k3*h));
g4=Gx2((x(i)+h),(y(i)+g3*h));
y(i+1)=y(i)+(1/6)*(k1+2*k2+2*k3+k4)*h;
z(i+1)=y(i)+(1/6)*(g1+2*g2+2*g3+g4)*h;

採用された回答

Birdman
Birdman 2018 年 4 月 4 日
In all of your for loop, even though your Fx1 and Gx2 functions are defined for one input argument, you try to pass two input arguments. You need to either change your code in for loop, or change your function definitions before for loop.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by