Not enough input arguments for ode45
4 views (last 30 days)
Show older comments
I am recieving an error for "Not enough input arguments.
Error in DoubleIP>@(t,Y,updated_state)DPIC(t,Y,updated_state) (line 175)
[time, state_values] = ode45(@(t,Y, updated_state) DPIC(t, Y, updated_state), tspan, IC);
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 104)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in DoubleIP (line 175)
[time, state_values] = ode45(@(t,Y, updated_state) DPIC(t, Y, updated_state), tspan, IC);"
This is a code snippet so certain details have been ommitted but I believe that these are the only details required for help. If more details are required I would be happy to provide them. Thank you in advance.
t0 = 0;
tf = 30;
tspan = [t0 tf];
% IC = [theta1 theta2];
IC = [x theta1 theta2 x_dot theta1_dot theta2_dot];
[time, state_values] = ode45(@(t,Y, updated_state) DPIC(t, Y, updated_state), tspan, IC);
x = state_values(:,1);
theta1 = state_values(:,2);
theta2 = state_values(:,3);
x_dot = state_values(:,4);
theta1_dot = state_values(:,5);
theta2_dot = state_values(:,6);
updated_state = [state_values(1);
state_values(2);
state_values(3);
state_values(4);
state_values(5);
state_values(6)];
function sdot = DPIC(t,Y,updated_state)
g = 9.8; % Gravitational Constant in [m/s^2]
L1 = 0.5; % Length of lower pendulum link in [m]
L2 = 0.75; % Length of upper pendulum link in [m]
m0 = 1.5; % Mass of cart in [kg]
m1 = 0.5; % Mass of lower pendulum link in [kg]
m2 = 0.75; % Mass of upper pendulum link in [kg]
l1 = (1/2)*L1; % Distance between the base of first pend. link and its center of mass
l2 = (1/2)*L2; % Distance between the base of second pend. link and its center of mass
I1 = (1/12)*m1*(L1)^2; % Moment of inertia of first pendulum link
I2 = (1/12)*m2*(L2)^2; % Moment of inertia of second pendulum link
K_lqr = [2.2361 -294.4233 7.2340 8.9417 -47.0216 -58.1944]';
desired_state = [0 0 0 0 0 0];
% u = @(time) 1;
u = @(time) -K_lqr*(updated_state - desired_state);
sdot = [ Y(2)
EQN1 (Place holders, **ignore) these equations do contain "u(t)"
Y(4)
EQN2 (Place holders, **ignore)
Y(6)
EQN3 (Place holders, **ignore)
];
end
0 Comments
Answers (1)
Walter Roberson
on 7 Mar 2024
[time, state_values] = ode45(@(t,Y, updated_state) DPIC(t, Y, updated_state), tspan, IC);
ode45() only has two values available to be passed: t and Y. ode45() is not going to pass in any updated_state
I'm not at all sure, but it looks like your code is expecting to use some sort of feedback mechanism -- to be given the "current" state but also to be given the "previous" state. That doesn't happen in ode45(): you are only ever given the "current" state.
4 Comments
Steven Lord
on 7 Mar 2024
So your differential equations looks more like the one at the top of this documentation page rather than the ones in the Types of ODEs section on this other documentation page? If so ode45 is not the right tool for the job; instead use one of the delay-differential equation solvers like dde23.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!