# Error coming as Not enough input arguments

1 回表示 (過去 30 日間)
Arjun Gupta 2022 年 7 月 3 日
コメント済み: Arjun Gupta 2022 年 7 月 3 日
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 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
Arjun Gupta 2022 年 7 月 3 日
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))
title('\theta')
subplot(2,2,4)
plot(t,x(:,4))
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

サインインしてコメントする。

### 回答 (1 件)

Raghav 2022 年 7 月 3 日

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.

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeLogical についてさらに検索

### Community Treasure Hunt

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

Start Hunting!