Not enough input arguements in a function

5 views (last 30 days)
Albert Kocik
Albert Kocik on 15 Nov 2021
Commented: Albert Kocik on 17 Nov 2021
Hello, I have a problem in my ode45 solver I can't solve, I am fairly new to MATLAB and so far the code makes sense to me but I can't get it working.
clc; clear;
p = [9.81 , 12 , 4000 , 100 , 8 , 6 , 6 , 1.5 , 7.5];
g = p(1);
m_B = p(2); M_CW = p(3);
M_P = p(4); L_B = p(5);
H = p(6); L_S = p(7);
L_BC = p(8); L_BP = p(9);
%z1(1)=thet
%z1(2)=omega%
dz = @(t1,z1) [z1(2);
-R1fun(z1(1),z1(2),p)/M1fun(z1(1),p)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
IC = [acos((-H)/(L_BP)),0]; T = 10;
opts = odeset('RelTol',1e-6,'Events',@COND);
[t1,z1] = ode45(dz,0:T,IC,opts);
Other than ode outputting complex values for angle and angular velocity, the code is not working with a given condition.
function [value,term,direction] = COND(t1,z1,p)
G = -R1fun(z1(1),z1(2),p)/M1fun(z1(1),p);
dv_s = dv_Sfun(z1(1),z1(2),G,p);
value = (dv_s/tan(acos((p(6)-p(9)*sin(z1(1)-pi/2))/p(7))))-p(1);
term = 1;
direction = 1;
end
Functions M1fun and R1fun are predefined and seem to be working good, R1 is taking 3 inputs (thet,omega,p) and M1 is taking (thet,p).
Error I am getting is:
Not enough input arguments.
Error in COND (line 3)
G = -R1fun(z1(1),z1(2),p)/M1fun(z1(1),p);
Error in odeevents (line 28)
eventValue = feval(eventFcn,t0,y0,eventArgs{:});
Error in ode45 (line 139)
odeevents(FcnHandlesUsed,odeFcn,t0,y0,options,varargin);
Error in aaabbbccc (line 22)
[t1,z1] = ode45(dz,0:T,IC,opts);
I appreciate all help, thank you in advance :)

Answers (1)

Stephen
Stephen on 15 Nov 2021
Edited: Stephen on 15 Nov 2021
The Events function is defined to have only two input arguments (not three like COND):
Solution: you need to parameterize the COND function handle, e.g.:
opts = odeset('RelTol',1e-6,'Events',@(t,y)COND(t,y,p));
  11 Comments
Albert Kocik
Albert Kocik on 17 Nov 2021
Does it work, or do you have no clue?

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!