Not enough input arguements in a function

2 visualizzazioni (ultimi 30 giorni)
Albert Kocik
Albert Kocik il 15 Nov 2021
Commentato: Albert Kocik il 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 :)

Risposte (1)

Stephen23
Stephen23 il 15 Nov 2021
Modificato: Stephen23 il 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 Commenti
Walter Roberson
Walter Roberson il 17 Nov 2021
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',@(t1,z1) COND(z1,p));
[t1,z1] = ode45(dz,0:T,IC,opts);
Unrecognized function or variable 'dv_Sfun'.

Error in solution>COND (line 43)
dv_s = dv_Sfun(z1(1),z1(2),G,p);

Error in solution (line 13)
opts = odeset('RelTol',1e-6,'Events',@(t1,z1) COND(z1,p));

Error in odeevents (line 28)
eventValue = feval(eventFcn,t0,y0,eventArgs{:});

Error in ode45 (line 139)
odeevents(FcnHandlesUsed,odeFcn,t0,y0,options,varargin);
function M1 = M1fun(thet,p)
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);
M1 = M_P.*(L_BP.*sin(thet).*(H+L_BP.*cos(thet)).*1.0./sqrt(-(H+L_BP.*cos(thet)).^2+L_S.^2)-(sqrt(2.0).*L_BP.*sin(thet.*2.0).*1.0./sqrt(-cos(thet.*2.0)+1.0))./2.0).^2+L_BC.^2.*M_CW+(L_B.^3.*m_B)./3.0+L_B.*L_BC.^2.*m_B-L_B.^2.*L_BC.*m_B;
end
function R1 = R1fun(thet,dthet,p)
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);
R1 = M_P.*(L_BP.*sin(thet).*(H+L_BP.*cos(thet)).*1.0./sqrt(-(H+L_BP.*cos(thet)).^2+L_S.^2)-sqrt(2.0).*L_BP.*cos(thet).*sin(thet).*1.0./sqrt(cos(thet).^2.*-2.0+2.0)).*(L_BP.*dthet.^2.*(cos(thet).^2-cos(thet).^4).*1.0./(sin(thet).^2).^(3.0./2.0)+(L_BP.*dthet.^2.*sin(thet).^2)./abs(sin(thet))-L_BP.^2.*dthet.^2.*sin(thet).^2.*1.0./sqrt(-(H+L_BP.*cos(thet)).^2+L_S.^2)-L_BP.*dthet.^2.*cos(thet).^2.*1.0./sqrt(-cos(thet).^2+1.0)+L_BP.*dthet.^2.*cos(thet).*(H+L_BP.*cos(thet)).*1.0./sqrt(-(H+L_BP.*cos(thet)).^2+L_S.^2)-L_BP.^2.*dthet.^2.*sin(thet).^2.*(H+L_BP.*cos(thet)).^2.*1.0./(-(H+L_BP.*cos(thet)).^2+L_S.^2).^(3.0./2.0))+g.*sin(thet).*((L_B.^2.*m_B)./2.0+L_BC.*M_CW-L_B.*L_BC.*m_B);
end
function [value,term,direction] = COND(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
Albert Kocik
Albert Kocik il 17 Nov 2021
Does it work, or do you have no clue?

Accedi per commentare.

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by