ODE 45 not working - not enough input arguments

1 view (last 30 days)
Hi, I'm having an issue with the code shown below. The main problem is with the ode45 solver and the number of variables involved:
function mdot=sim1(t,p,q)
%
Vm=1;
I1=800;
I2=3200;
R1=4000;
R2=800;
C1=1e-5;
C2=5e-6;
M=0.1;
rp=.02;
Ft=0;
A=3.14159*(rp^2);% area of the piston pushing into hydraulic system
n=Vm*A; %relation between TF from V to Q
I=M;
%
p2dot=(Ft/(1+n^2*(I1/I)))+((R1*n^2*(1/I)*p(2))/(1+n^2*(I1/I)))+((n*(1/C1)*q(8))/(1+n^2*(I1/I)));
q8dot=(n*(1/I)*p(2))-((1/I(2))*p(10));
p10dot=((1/C1)*q(8))-(R2*(1/I1)*p(10))-((1/C2)*q(12));
q12dot=(1/I2)*p(10);
%
mdot=[p2dot;q8dot;p10dot;q12dot];
The function is coupled with this code:
clear all
clc
%
tspan=[0 100]; % Time range, [s]
x0=[0;0;0;0]; % Initial momentum and displacement values
%
[t,x]=ode45(@sim1,tspan,x0);
%
% Plot results
When I try to run the code, these errors pop up:
Not enough input arguments.
Error in sim1 (line 16)
p2dot=(Ft/(1+n^2*(I1/I)))+((R1*n^2*(1/I)*p(2))/(1+n^2*(I1/I)))+((n*(1/C1)*q(8))/(1+n^2*(I1/I)));
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in DSCSim1 (line 10)
[t,x]=ode45(@sim1,tspan,x0);
How would I go about trying to fix this? I don't exactly know how many or what input arguments I need in order to make the code run. I also don't understand the error I'm getting in sim1 line 16, or in DSCsim1 line 10. Any help would be greatly appreciated.
  2 Comments
madhan ravi
madhan ravi on 6 Apr 2020
Would it be possible to upload the equations in Latex form?

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 6 Apr 2020
ode45( ) requires that the derivative function handle have the specific arguments (t,y), where y is a single state vector. But you have this signature
function mdot=sim1(t,p,q)
That's three arguments, hence the error.
You need to rewrite the sim1 function with a (t,y) input argument list, and extract your p and q variables from y, which will be a 4-element vector.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!