if true % clc;
clear all;close all;%to=0;
tf=10;d=.001;n=tf/d;y=zeros(1,n);r=zeros(1,n);x=zeros(2,n);s=zeros(1,n);u=zeros(1,n);v=zeros(1,n);sdot=zeros(1,n);ssdot=zeros(1,n);t=zeros(1,n);e=zeros(2,n);c=23;M=0.6;u(1,1)=0;for i=1:n+1 dx1=x(2,i); dx2=3*x(1,i)+u(1,i); x(1,(i+1))=x(1,i)+(d*dx1); x(2,(i+1))=x(2,i)+(d*dx2); t(1,(i+1))=t(1,i)+d; xd(1,(i+1))=sin(t(1,i)); xd(2,(i+1))=cos(t(1,i)); e(1,(i+1))=x(1,i+1)-xd(1,i+1); e(2,(i+1))=x(2,i+1)-xd(1,i+1); s(1,(i+1))=c*e(1,1+i)+e(2,1+i); v(1,i)=-sin(t(1,i))-10*x(1,i)+c*cos(t(1,i))-c*x(2,i); u(1,i)=v(1,i)-M*sign(s(1,i)); sdot(1,i)=c*(x(2,i)-cos(t(1,i)))+dx2+sin(t(1,i)); ssdot(1,i)=s(1,i)*sdot(1,i); u(1,i+1)=v(1,i)-M*sign(s(1,i)); y(1,i+1)=x(1,i+1); y(2,i+1)=x(2,i+1);endfigure(1)plot(t(1,:),xd(1,:),'r',t(1,:),y(1,:),'b','linewidth',2);legend('Ideal angular position','Actual Angular Position');xlabel('time(s)');ylabel('Position tracking x1');xlabel('e1');ylabel('e2');figure(2)plot(t(1,:),ssdot(1,:),'g','linewidth',2);end
MATLAB: The plot for t and ssdot in the following code cannot be displayed as it shows a vector length mismatch. Please suggest how I can get around it…
errorplots
Best Answer