"Not Enough Input Arguments" Error Calling ODE45
11 次查看(过去 30 天)
显示 更早的评论
Hello:
I am running into "not enough input arguments" when calling ODE45 for a system of differential equations defined in the function below. Can you help me determine what I need to fix? The line throwing the error is line 12 where I define rdot.
function dz = sys(t,z)
b = 1000;
bT = 250;
k=17000;
kT=136000;
m1=300;
m2=30;
A = [0 0 1 -1;0 0 0 1; -k/m1 0 -b/m1 b/m1;k/m2 -kT/m2 b/m2 -(b+bT)/m2];
B = [0;-1;0;bT/m2];
rdot = -9.42*0.05*sin(9.42*t);
dz = A*z + B*rdot;
end
I tried to put this into the form of dx = A*x + B*u, where u is the input function into the system (represented in my function as rdot), but whenever I try to call ODE45 it gives me a "not enough input arguments" error.
This is how I am calling ODE45 in Matlab:
[t,z] = ode45(@sys,[0:0.1:100],0)
For a little more background - I am trying to solve a state-space representation of differential equations representing a quarter car model, with the sprung mass being represented as m1, k, b and the unsprung mass by m2, kT, bT.
I attached a screenshot of the written out form of the DE system. P1, P2 are the suspension stroke and tire deflection respectively. V1, V2 are the velocities of the sprung and unsprung masses respectively.
0 个评论
回答(2 个)
Walter Roberson
2025-10-11
[t,z] = ode45(@sys,[0:0.1:100],0)
You are passing a single initial state, the 1x1 value 0, into sys. The result of calling sys needs to be a single output state, 1 x 1. But instead dz is 4 x 4.
dz comes out 4 x 4 because your z value is scalar instead of 4 x 1. If you were passing a 4 x 1 initial state instead of a 1 x 1 initial state then your dz would come out as 4 x 1.
1 个评论
Walter Roberson
2025-10-11
By the way, there is no error about missing inputs.
[t,z] = ode45(@sys,[0:0.1:100],0)
function dz = sys(t,z)
b = 1000;
bT = 250;
k=17000;
kT=136000;
m1=300;
m2=30;
A = [0 0 1 -1;0 0 0 1; -k/m1 0 -b/m1 b/m1;k/m2 -kT/m2 b/m2 -(b+bT)/m2];
B = [0;-1;0;bT/m2];
rdot = -9.42*0.05*sin(9.42*t);
dz = A*z + B*rdot;
whos A z B rdot dz
end
Sam Chak
2025-10-11
Hi @Henry
The quarter car system has four states: {P1, P2, V1, V2}. When using the ode45 solver, it is necessary to supply four known initial values for these states. In the demo below, the initial state values at time
are assumed to be zeros, indicating zero deflections and zero velocities.
% simulation time interval
tspan = [0, 4];
% initial state values at time t = 0
z0 = [0; % P1(0) = 0
0; % P2(0) = 0
0; % V1(0) = 0
0]; % V2(0) = 0
% call ode45 to solve the dynamic state-space equations
[t, z] = ode45(@sys, tspan, z0);
% plot results
plot(t, z), grid on
xlabel('time, t')
ylabel('amplitude')
legend('P_1', 'P_2', 'V_1', 'V_2')
% quarter car system
function dz = sys(t, z)
% parameters
b = 1000;
bT = 250;
k = 17000;
kT = 136000;
m1 = 300;
m2 = 30;
% matrices
A = [0 0 1 -1;
0 0 0 1;
-k/m1 0 -b/m1 b/m1;
k/m2 -kT/m2 b/m2 -(b+bT)/m2];
B = [0;
-1;
0;
bT/m2];
% input
rdot= -9.42*0.05*sin(9.42*t);
% state space
dz = A*z + B*rdot;
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
