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.
0 Comments
Sign in to comment.