Questions about the inverted pendulum function.

4 visualizzazioni (ultimi 30 giorni)
O Kyung Kwon
O Kyung Kwon il 22 Nov 2020
Risposto: Nikhil Sonavane il 25 Nov 2020
I wrote the following functions using a nonlinear model. Myfun is a function that creates an inverted pendulum model, and the drawcartpend function is a function that draws a pendulum.
At this time, the following problems occur in each function, and I want to get an answer for them.
myfun function
>>>Myfun
function dx = myfun(x, M, m, L, g, b, u)
Sx = sin(x)(3));
Cx = cos(x(3));
dx(1,1) = x(2);
dx(2,1) = 1/(M+m-m*Cx*Cx)*(-b*x(2)+m*g*Cx*Sx+M*x(4)*Sx+u);
dx(3,1) = x(4);
dx(4,1) = -g/L*Sx-Cx/((M+m-m*Cx*Cx)*L*(-b*x2)+m*g*Cx*Sx*M*x(4)*Sx+u);
M = 3;
m = 1;
L = 2;
g = 10;
b = 0.5;
u = 0;
tspan = 0:.1:15;
x0 = [2*pi/3; .5];
[t,x] =ode45 (@(t,x)pend(x,m,L,g,b),tspan,x0);
>>error
Insufficient input arguments.
Value entered for variables M and u is not used.
It is not possible to verify that the variables t and x are interpolated.
drawcartpend function
>>>Drawcartpend
function drawcartpend(x,L)
th = x(3); %theta
% draw the horizontal line
plot([-10 10],[0 0]',w','LineWidth',2)
Axis equal
hold on
% draw the pendulum line
x = L*sin(th);
y = -L*cos(th);
plot([0 x],[0 y]'w','LineWidth',2)
% draw the circle ball
bsize = 0.4; %ball dimeter
viscircles ([x, y], bsize/2);
% defined limits and colors
xlim([-5 5]);
ylim([-2.5 2.5]);
set (gca'Color',[0 0 0]', XColor,'w','YColor','w')
% box off
Drawnow
hold off
for k=1:length(t)
drawcartpend(x(k,:), L);
pause (0.01)
End
>>error
Insufficient input arguments.
Please reply as soon as possible.

Risposte (1)

Nikhil Sonavane
Nikhil Sonavane il 25 Nov 2020
From what I understand, you have declared input variables to their values inside the function itself. If they are just some constants there is not need of putting them into input arguments of the function. You may refer to function for more information on functions.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by