# Error: Not enough input arguments

1 visualización (últimos 30 días)
Sam Butler el 6 de En. de 2023
Comentada: Sam Butler el 7 de Feb. de 2023
Hello,
I am using the ode45 function to solve three second order equations (theta_double dot 1, theta_double dot 2 and theta_double dot n) to produce torque deflection characteristics. I have typed this code following a few tutorials on youtube.
Does anyone know why I am getting an error saying 'Not enough input arguments'?
*I am quite new to MATLAB*
Code:
syms J1 J2 Jn c1 c2 cn k1 k2 kn knl q w x(t) y(t) z(t) T Y
% let ddtheta(1)=x, ddtheta(2)=y, ddtheta(n)=z, dtheta_out=q. theta_out=w
Eq1 = diff(x,2) == (-c1*((diff(x)-q) - k1*(x-w) ...
+ c2*(diff(y)-diff(x)) + k2*(y-x) + cn*(diff(z)-diff(x))...
+ kn*(z-x) + knl*(z-x)^5))/J1;
Eq2 = diff(y,2) == ((-c2*(diff(y)-diff(x)))-(k2*(y-x)))/J2;
Eq3 = diff(z,2) == ((-cn*(diff(z)-diff(x)))-(kn*(z-x))-(knl*(z-x)^5))/Jn;
[VF,Sbs] = odeToVectorField(Eq1,Eq2,Eq3);
coupled_vanderpol = matlabFunction(VF, 'Vars',{J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y});
%Parameters
J1 = 2.08e-4;
J2 = 2.931e-3;
Jn = 4.0085e-4;
c1 = 0.15;
c2 = 0.2;
cn = 0.015;
k1 = 270;
k2 = 8500;
kn = 10.89;
knl = 38870;
%Velocity input
tspan = [0,100];
thetadot0 = 800; % mean motor speed (rpm)
q = thetadot0 + theta1dot*cos(36*2*pi*f_mech*tspan) ...
+ theta2dot*cos(2*36*2*pi*f_mech*tspan);
C=0;
w = thetadot0*tspan + (theta1dot*sin(72*pi*f_mech*tspan))/(72*pi*f_mech) ...
+ (theta2dot*sin(144*pi*f_mech*tspan))/(144*pi*f_mech) + C;
%Initial Conditions
%Plot
[t,v_z] = ode45(@(T,Y)coupled_vanderpol({J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y}),tspan,t0);
figure
plot(t, v_z)
grid
Error:
Not enough input arguments.
Error in symengine>@(J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y)[Y(2);-(c2.*(Y(2)-Y(4))+k2.*(Y(1)-Y(3)))./J2;Y(4);(c1.*(q+knl.*(Y(3)-Y(5)).^5-Y(4)-k1.*(w-Y(3))-c2.*(Y(2)-Y(4))+cn.*(Y(4)-Y(6))-k2.*(Y(1)-Y(3))+kn.*(Y(3)-Y(5))))./J1;Y(6);(knl.*(Y(3)-Y(5)).^5+cn.*(Y(4)-Y(6))+kn.*(Y(3)-Y(5)))./Jn]
Error in trial>@(T,Y)coupled_vanderpol({J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y}) (line 41)
[t,v_z] = ode45(@(T,Y)coupled_vanderpol({J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y}),tspan,t0);
Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in trial (line 41)
[t,v_z] = ode45(@(T,Y)coupled_vanderpol({J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y}),tspan,t0);
Thank you!!
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Bora Eryilmaz el 6 de En. de 2023
Editada: Bora Eryilmaz el 6 de En. de 2023
There are probably other array concatenation issues in your equation definitions, but regarding your current issue, remove the curly braces inside the coupled_vanderpol(...) call:
% Not this
%[t,v_z] = ode45(@(T,Y)coupled_vanderpol({J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y}),tspan,t0);
% But this
%[t,v_z] = ode45(@(T,Y)coupled_vanderpol(J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y),tspan,t0);
See the updated example below:
syms J1 J2 Jn c1 c2 cn k1 k2 kn knl q w x(t) y(t) z(t) T Y
% let ddtheta(1)=x, ddtheta(2)=y, ddtheta(n)=z, dtheta_out=q. theta_out=w
Eq1 = diff(x,2) == (-c1*((diff(x)-q) - k1*(x-w) ...
+ c2*(diff(y)-diff(x)) + k2*(y-x) + cn*(diff(z)-diff(x))...
+ kn*(z-x) + knl*(z-x)^5))/J1;
Eq2 = diff(y,2) == ((-c2*(diff(y)-diff(x)))-(k2*(y-x)))/J2;
Eq3 = diff(z,2) == ((-cn*(diff(z)-diff(x)))-(kn*(z-x))-(knl*(z-x)^5))/Jn;
[VF,Sbs] = odeToVectorField(Eq1,Eq2,Eq3);
coupled_vanderpol = matlabFunction(VF, 'Vars',{J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y});
%Parameters
J1 = 2.08e-4;
J2 = 2.931e-3;
Jn = 4.0085e-4;
c1 = 0.15;
c2 = 0.2;
cn = 0.015;
k1 = 270;
k2 = 8500;
kn = 10.89;
knl = 38870;
% Similar to what ode45 is doing
T = 0;
Y = 1:6;
% Not this:
% coupled_vanderpol({J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y})
% But this
coupled_vanderpol(J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y)
ans =
ode45 is probably calling the function with a Y vector that has a different size than 6, which results in array concatenation issues like this:
Y = 1:5;
coupled_vanderpol(J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y)
Index exceeds the number of array elements. Index must not exceed 5.

Error in symengine>@(J1,J2,Jn,c1,c2,cn,k1,k2,kn,knl,q,w,T,Y)[Y(2);-(c2.*(Y(2)-Y(4))+k2.*(Y(1)-Y(3)))./J2;Y(4);(c1.*(q+knl.*(Y(3)-Y(5)).^5-Y(4)-k1.*(w-Y(3))-c2.*(Y(2)-Y(4))+cn.*(Y(4)-Y(6))-k2.*(Y(1)-Y(3))+kn.*(Y(3)-Y(5))))./J1;Y(6);(knl.*(Y(3)-Y(5)).^5+cn.*(Y(4)-Y(6))+kn.*(Y(3)-Y(5)))./Jn]
I believe ode45 can call the function for Y values corresponding to multiple time points, in which case your code needs to be able to handle a matrix of Y values, which would have 6 columns and as many rows as the time points.
##### 4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
Bora Eryilmaz el 6 de En. de 2023
You will have to figure out how to structure the equations' output yourself.
For ode45, if you have three equations and three variables, you need to return a Y matrix with 3 columns and as many rows as in T that was passed in by ode45.
You also don't need to use symbolic math here. Just create a regular MATLAB function to encode your differential equations. Also, please read the examples more carefully: https://www.mathworks.com/help/matlab/ref/ode45.html#bu00_4l_sep_shared-odefun
Sam Butler el 7 de Feb. de 2023
I have spent more time trying to do this however I have not made a great deal of progress. Would it be possible to speak further with you about this? possibly over a call.

Iniciar sesión para comentar.

### Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by