How to solve this system of ODE's

조회 수: 2 (최근 30일)
Danny Helwegen
Danny Helwegen 2019년 2월 6일
댓글: Star Strider 2019년 2월 7일
Hi i have a rather simple question, I need to solve a system of ode's of the form Ax = b with given A and timespan and interval.
A = [-199 -198; 99 98]
To solve this i wrote the following code:
function dxdt = System()
dxdt = zeros (2,2);
dxdt(1) = -199*x(1) - 198*x(2);
dxdt(2) = 99*x(1) + 98*x(2);
dxdt = dxdt';
end
And:
[t,x] = ode45(@System, [0 2.5], [1 1])
plot(t,x)
The error that i get is:
Error using System
Too many input arguments
Does someone see where i went wrong?

채택된 답변

Star Strider
Star Strider 2019년 2월 6일
Your ODE funciton has to have your independent and dependent variables (here ‘t’ and ‘x’) as arguments.
Try this:
function dxdt = System(t,x)
dxdt = zeros (2,1);
dxdt(1) = -199*x(1) - 198*x(2);
dxdt(2) = 99*x(1) + 98*x(2);
end
[t,x] = ode45(@System, [0 2.5], [1 1]);
plot(t,x)
  댓글 수: 2
Danny Helwegen
Danny Helwegen 2019년 2월 7일
Thanks, I completly forgot about them
Star Strider
Star Strider 2019년 2월 7일
As always, my pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by