Package: mlx2md
MATLAB.mlxto Markdown.mdConverterInstallationpip install mlx2mdUsagepython -m mlx2md -i example.mlxExample Converted CodeMATLAB LIVE SCRIPTSystem Definitionclcclearsymsx1x2x3x4x5x6x7x8u_xu_y;% System's TypeMIMO=1;% constantsm=0.11;Ib=1.76e-5;rb=0.02;b=m/(m+Ib/rb^2)g=9.81;% Non-linear system's state-spaceX=[x1x2x3x4x5x6x7x8];U=[u_xu_y];f=[x2;b*(x1*x4*x4+x4*x5*x8-g*sin(x3));x4;u_x;x6;b*(x5*x8*x8+x1*x4*x8-g*sin(x7));x8;u_y;];% Linearized system's state-spaceAs=jacobian(f,X);A=subs(As,[X,U],[0000000000]);A=double(A)n=length(A);Bs=jacobian(f,U);B=subs(Bs,[X,U],[0000000000]);B=double(B)[~,p]=size(B);C=[10000000;00001000][l,~]=size(C);D=zeros(l,p)sys=ss(A,B,C,D);G=tf(sys)Input_1_to_ouput1=G(1,2)Input_2_to_ouput2=G(2,1)% Input_1_to_ouput1 is equal to Input_2_to_ouput2 so can% split A into two SISO systemA_X=[010000-g*b000010000]B_X=[0;0;0;1]C_X=[1000]D_X=[0]rank(obsv(A,C))% == 8rank(ctrb(A,B))% == 8%% so our system is minimaldesired_OS=10;Ts=1;zita=0.59;w=6.77;sd_1=-zita*w+w*sqrt(zita^2-1)sd_2=-zita*w-w*sqrt(zita^2-1)sd_3=-20sd_4=-30K_X=place(A_X,B_X,[sd_1sd_2sd_3sd_4])K=[K_X0000;0000K_X]controlled_tf=tf(ss(A_X-B_X*K_X,B_X,C_X,D_X))static_compensator=evalfr(controlled_tf,0)^(-1);step(static_compensator*controlled_tf);t=linspace(0,20,1000);% Time Vectoru=sin(t);% Forcing Functiony=lsim(static_compensator*controlled_tf,u,t);% Calculate System Responsefigure(1)plot(t,y,t,u)gridA_bar=[A_Xzeros(4,1);-C_Xzeros(1,1)];B_bar=[B_X;zeros(1,1)];k_new=place(A_bar,B_bar,[sd_1,sd_2,sd_3,sd_4,-40])k_d=[k_new(1:4)0000;0000k_new(1:4)]dynamic_pre_comp=[-k_new(:,5:end)0;0-k_new(:,5:end)]RESULTSb(1x1):0.7143A(8x8) double:0    1.0000         0         0         0         0         0         0
         0         0   -7.0071         0         0         0         0         0
         0         0         0    1.0000         0         0         0         0
         0         0         0         0         0         0         0         0
         0         0         0         0         0    1.0000         0         0
         0         0         0         0         0         0   -7.0071         0
         0         0         0         0         0         0         0    1.0000
         0         0         0         0         0         0         0         0B(8x2) double:0     0
     0     0
     0     0
     1     0
     0     0
     0     0
     0     0
     0     1C(2x8) double:1     0     0     0     0     0     0     0
     0     0     0     0     1     0     0     0D(2x2) double:0     0
     0     0G =
 
  From input 1 to output...
       -7.007
   1:  ------
        s^4
 
   2:  0
 
  From input 2 to output...
   1:  0
 
       -7.007
   2:  ------
        s^4
 
Continuous-time transfer function.Input_1_to_ouput1 =
 
  0
 
Static gain.Input_2_to_ouput2 =
 
  0
 
Static gain.A_X(4x4) double:0    1.0000         0         0
         0         0   -7.0071         0
         0         0         0    1.0000
         0         0         0         0B_X(4x1) double:0
     0
     0
     1C_X(1x4) double:1     0     0     0D_X(1x1):0ans(1x1):8ans(1x1):8sd_1(1x1):-3.9943 + 5.4661isd_2(1x1):-3.9943 - 5.4661isd_3(1x1):-20sd_4(1x1):-30K_X(1x4) double:1.0e+03 *

   -3.9245   -1.0111    1.0453    0.0580K(2x8) double:1.0e+03 *

   -3.9245   -1.0111    1.0453    0.0580         0         0         0         0
         0         0         0         0   -3.9245   -1.0111    1.0453    0.0580controlled_tf =
 
                     -7.007
  ---------------------------------------------
  s^4 + 57.99 s^3 + 1045 s^2 + 7085 s + 2.75e04
 
Continuous-time transfer function.k_new(1x5) double:1.0e+05 *

   -0.4437   -0.0698    0.0336    0.0010    1.5698k_d(2x8) double:1.0e+04 *

   -4.4368   -0.6978    0.3365    0.0098         0         0         0         0
         0         0         0         0   -4.4368   -0.6978    0.3365    0.0098dynamic_pre_comp(2x2) double:1.0e+05 *

   -1.5698         0
         0   -1.5698k_new(1x5) double:1.0e+05 *

   -0.4437   -0.0698    0.0336    0.0010    1.5698