Error coming as Not enough input arguments

2 views (last 30 days)
function dx = invpen(t,x)
M = 3;
m = 0.4;
I = 1.5;
g = 9.8;
b = 1;
U = 0;
dx=zeros(4,1);
dx(1)=x(2);
dx(2)=((-g*m*sin(x(3))*cos(x(3))) + (m*l*(x(4))^2*sin(x(3))) + (m*b*x(4)*cos(x(3))) + U)/(M+(1-(cos(x(3))*cos(x(3))))*m);
dx(3)=x(4);
dx(4)=(((M+m)*((b*x(4))-(g*sin(x(3))))) + (m*l*(x(4))^2^sin(x(3))+cos(x(3)))+ (U*cos(x(3))))/(l*((m*cos(x(3))*cos(x(3)))-M-m));
end
  2 Comments
Karan Kannoujiya
Karan Kannoujiya on 3 Jul 2022
Hi Arjun,
Could you please send how you calling the function and the value of x and t you are passing in function.
Arjun Gupta
Arjun Gupta on 3 Jul 2022
clc
clear all
close all
L = 1.5;
t = 0:0.01:10;
x0 = [0.5 0 pi/2 0];
[t x]=ode45('invpend',t,x0);
figure
subplot(2,2,1)
plot(t,x(:,1))
xlabel('Time(sec)'), ylabel('m')
title('x')
subplot(2,2,2)
plot(t,x(:,2))
xlabel('Time(sec)'), ylabel('m/s')
title('x^{.}')
subplot(2,2,3)
plot(t,x(:,3))
xlabel('Time(sec)'), ylabel('rad')
title('\theta')
subplot(2,2,4)
plot(t,x(:,4))
xlabel('Time(sec)'), ylabel('rad/sec')
title('\theta^{.}')
X0 = 0;
Y0 = 0;
for i = 1:length(t)
Xc = x(i,1);
Xp = x(i,1) + L * sin(pi - x(i,3));
Yp = L * cos(pi - x(i,3));
figure(2)
plot([-3 5], [0 0], 'linewidth', 6, 'color', 'g');
axis([-4 6 -4 4]);
line([Xc Xp], [Y0, Yp], 'linewidth', 2, 'color', 'b');
hold on
plot(Xc, Y0, 's', 'markersize', 30, 'markerfacecolor', 'y');
plot(Xp, Yp, 'o', 'markersize', 15, 'markerfacecolor', 'r');
hold off
end

Sign in to comment.

Answers (1)

Raghav
Raghav on 3 Jul 2022
Edited: Raghav on 3 Jul 2022
There are a few problems in this function.
First input argument 't' is not used anywhere in the function, so you can remove it from input argument list to remove this warning.
Second, the variable 'l' used in the calculation of dx(2) and dx(4)is not defined, also the variable 'ɪ' you defined is not used anywhere in the function, so I guess in the original formula, there was 'ɪ' instead of 'l' like:
dx(2)=((-g*m*sin(x(3))*cos(x(3))) + (m*I*(x(4))^2*sin(x(3))) + (m*b*x(4)*cos(x(3))) + U)/(M+(1-(cos(x(3))*cos(x(3))))*m);
and
dx(4)=(((M+m)*((b*x(4))-(g*sin(x(3))))) + (m*I*(x(4))^2^sin(x(3))+cos(x(3)))+ (U*cos(x(3))))/(I*((m*cos(x(3))*cos(x(3)))-M-m));
If you still face the error- "Not enough input arguments", call the function "invpen" with proper x, x should be an array of size atleast 4.

Tags

Community Treasure Hunt

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

Start Hunting!