%the error
Not enough input arguments.
Error in Exam2>odefun (line 92)
f=[0 ; (2*f0-f0.*heaviside(t,t1)-2*f0.*heaviside(t,t2))];
Error in Exam2 (line 65)
[t,x]=ode45(odefun,tspan,IC);
%my ode45 call
IC=[x0 v0];
tspan=0:dt:tf;
[t,x]=ode45(odefun,tspan,IC);
%my function
function xdot=odefun(t,x)
global f0 wn t1 t2
A=[0 1 ; -wn^2 0];
f=[0 ; (2*f0-f0.*heaviside(t,t1)-2*f0.*heaviside(t,t2))];
xdot=A*x+f;
end

 採用された回答

Steven Lord
Steven Lord 2020 年 11 月 6 日

0 投票

[t,x]=ode45(odefun,tspan,IC);
This attempts to call your odefun function with 0 input arguments and use the function handle it returns as the first input argument to ode45. If you want the first input argument to ode45 to be a function handle to odefun (you want ode45 to use odefun to evaluate the right-hand side of your system of ODEs), you need to add one character.
[t,x]=ode45(@odefun,tspan,IC);

その他の回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 11 月 6 日

0 投票

Have you created your own heaviside function? The one created by MathWorks only accepts a single input. The one you are using has 2, and apparently expects more.

1 件のコメント

Michael Abend
Michael Abend 2020 年 11 月 6 日
ok so that has to be the issue thank you?

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

カテゴリ

製品

タグ

質問済み:

2020 年 11 月 6 日

回答済み:

2020 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by