I am trying to write this function for ode. But it always gives me an error as not enough input arguments. Here is my code associated:

4 ビュー (過去 30 日間)
I am trying to write this function for ode. But it always gives me an error as not enough input arguments. Here is my code associated:
function dxdt = odefcn(x,a)
dxdt = zeros(3,1);
dxdt(1) = x(2);
dxdt(2) = x(3);
dxdt(3) =-a*x(3)+x(2)-x(1);
end

採用された回答

Walter Roberson
Walter Roberson 2017 年 9 月 2 日
Do not use
ode45( odefcn, .....)
Use
ode45( @odefcn, .....)
  5 件のコメント
Walter Roberson
Walter Roberson 2017 年 9 月 2 日
a=2
tspan = [0 5];
X0 = ones(1,3);
[t,x] = ode45(@(t,x) odefcn(x,a), tspan, X0);
figure;
plot(t,x);
grid on;
with
function dxdt = odefcn(x,a)
dxdt = zeros(3,1);
dxdt(1) = x(2);
dxdt(2) = x(3);
dxdt(3) =-a*x(3)+x(2)-x(1);
end
Sam17
Sam17 2017 年 9 月 2 日
Thankyou for your help. I did solve it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by