필터 지우기
필터 지우기

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by