Why do I receive 'not enough input arguments' in ode45

1 view (last 30 days)
Hello all,
I am trying to find the solution to a N links system with Lagrange constraints, using ode45. I have defined the relevant matrices and formatted them as matlabFunction for the ode45 to use.
When calling the ode45 function I repeatedly get the following error:
Not enough input arguments.
Gtemp=G(z);
Error in not_working (line 69)
[t,z] = ode45(@(t,z) odefcn4(t,z,M,G,C,W,Wd), tint, IC);
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);
My code is as follows:
clc;close all;
N=5;
syms u [1 N] real
syms u_d [1 N] real
syms v [1 N] real
syms v_d [1 N] real
syms theta [1 N] real
syms theta_d [1 N] real
syms m I k c w d l delta L v0 t_sym real
svars= [m I k c w d l delta L v0];
L_val=2; v0_val=1;
vars=[1 1 1 1 1 1 N/L_val 0.2 2 1];
q=[u v theta]; %DOF vector, length 3*N
q_d=[u_d v_d theta_d]; %DOF derivative vector
T=sum(m/2.*(u_d.^2+v_d.^2)+I/2.*(theta_d).^2); %Kinetic Energy
V=0.5*k*theta1^2;
for i=2:N
V= V+0.5*k*(theta(i)-theta(i-1))^2; % Potential Energy
end
D=sum(0.5*c.*theta_d.^2); %Dissipation Energy
h=sym(zeros(1,2*N+2));
h(1)=u1-d/2;
h(1+N)=v1-v0*t_sym-w/2;
h(1+2*N)=theta1;
for i=2:N
h(i)=u(i)-u(i-1)-(l/2)*cos(theta(i))-(l/2)*cos(theta(i-1));
h(i+N)=v(i)-v(i-1)-(l/2)*sin(theta(i))-(l/2)*sin(theta(i-1)); %Constraints, length 2*N+2
end
h(2*N+2)=d/2+L-delta-(u(N)+(l/2)*cos(theta(N)));
W=sym(zeros(length(h),length(q)));
Wd=sym(zeros(length(h),length(q)));
for i=1:length(h)
W(i,:)=gradient(h(i),q);
for j=1:length(q)
Wd(i,j)=gradient(W(i,j),q)'*q_d';
end
end
M=hessian(T,q_d);
G=gradient(V,q);
C=gradient(D,q_d); %Lagrangian formulation
M=double(subs(M,svars,vars));
G=matlabFunction(subs(G,svars,vars),'Vars',[q q_d]);
C=matlabFunction(subs(C,svars,vars),'Vars',[q q_d]);
W=matlabFunction(subs(W,svars,vars),'Vars',[q q_d]);
Wd=matlabFunction(subs(Wd,svars,vars),'Vars',[q q_d]);
tint=[0 10];
IC=zeros(1,6*N);
IC(1,3*N+1)=v0_val;
IC(1,1:N)=(0:L_val/N:L_val-L_val/N)+L_val/(2*N);
[t,z] = ode45(@(t,z) odefcn4(t,z,M,G,C,W,Wd), tint, IC);
and the function odefcn4 is deifned as:
function dzdt = odefcn4(t,z,M,G,C,W,Wd) % Isolating the second derivative part of the constraints equation
N=length(M(1,:)/3);
Gtemp=G(z);
Ctemp=C(z);
Wtemp=W(z);
Wdtemp=Wd(z);
LHS=zeros(5*N+2,5*N+2);
LHS(1:3*N,1:3*N)=M;
LHS(1:3*N,(3*N+1):5*N+2)=-Wtemp';
LHS((3*N+1):(5*N+2),1:3*N)=Wtemp;
RHS=zeros((5*N+2),1);
RHS(1:3*N,1)=-Ctemp-Gtemp;
RHS((3*N+1):(5*N+2),1)=-Wdtemp*z(1:(3*N))';
eq=LHS\RHS;
dzdt=[z((3*N+1):(5*N+2)); eq(1:3*N)];
end
Thank you for your help
  1 Comment
Torsten
Torsten on 25 May 2022
Did you look at the list of input parameters to M,G,C,W and Wd after transforming them to functions with the "matlabFunction" command ? This calling list must be used when you call the functions in odefcn4.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 25 May 2022
G=matlabFunction(subs(G,svars,vars),'Vars', {[q q_d]} );
C=matlabFunction(subs(C,svars,vars),'Vars', {[q q_d]} );
W=matlabFunction(subs(W,svars,vars),'Vars', {[q q_d]} );
Wd=matlabFunction(subs(Wd,svars,vars),'Vars', {[q q_d]} );

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!