I'm having trouble with ode45. It keeps getting the "not enough input arguments" error.

1 次查看(过去 30 天)
I'm trying to solve the problem 3.10.1 from the book Engineering Vibrations, from Inman, but I keep getting the ''not enough input arguments'' error for reasons I don't understand. My code being:
clear
xo=[0.01 1];
ts=[0,8];
[t,x]=ode45(f,ts,xo);
Not enough input arguments.

Error in solution>f (line 14)
v=[x(2); x(2).*-2*zeta*wn + x(1).*-wn^2 - x(1)^3.*alpha + Fo/m*(stepfun(t,t1)-stepfun(t,t2))];
plot(t, x(:,1)); hold on % The response of nonlinear system
[t,x]=ode45(f1,ts,xo);
plot(t,x(:,1),'——'); hold off % The response of linear system
%---------------------------------------------
function v= f(t,x)
m=100; k=2000; c=20; wn=sqrt(k/m); zeta=c/2/sqrt(m*k); Fo=1500;
alpha=3; t1=1.5; t2=5;
v=[x(2); x(2).*-2*zeta*wn + x(1).*-wn^2 - x(1)^3.*alpha + Fo/m*(stepfun(t,t1)-stepfun(t,t2))];
end
%---------------------------------------------
function v= f1(t,x)
m=100; k=2000; c=20; wn=sqrt(k/m); zeta=c/2/sqrt(m*k); Fo=1500;
alpha=0; t1=1.5; t2=5;
v=[x(2); x(2).*-2*zeta*wn + x(1).*-wn^2 - x(1)^3.*alpha+ Fo/m*(stepfun(t,t1)-stepfun(t,t2))];
end

采纳的回答

Torsten
Torsten 2022-7-17
[t,x]=ode45(@f,ts,xo);
instead of
[t,x]=ode45(f,ts,xo);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by