Question: Convert the Code below from MATLAB to Mathematica Urgent Please: The matlab script is clear all close all clc %% The system syms s A
Convert the Code below from MATLAB to Mathematica Urgent Please:
The matlab script is
clear all close all clc %% The system syms s A = [ -3 1 0 0 0 ; 0 0 1 0 0 ; 10 -6 -2 0 2 ; 0 0 0 0 1 ; -6 2 0 -1 -6 ]; B = [ 1 0 ; 0 0 ; 3 1 ; 0 0 ; 2 1 ]; C = [ 1 0 0 0 0 ; 0 1 0 0 0 ; 0 0 0 1 0 ]; D = [ 0 0 ; 0 0 ; 0 0]; n = length(A); m = length(B(1,:)); p = length(C(:,1)); x0 = zeros(n , 1); %% Tuning the gain for the state-feedback P = [ -3 -4 -4.01 -5 -5.01 ]; K = place( A , B , P ); %% First simulation ti = linspace( 0 , 10 , 1000 ); tspan = ti; [t,x] = ode45(@(t,x) DiffEcus(t,x, A-B*K , B ), tspan, x0 ); x = x'; y = C*x + 0; %% Tunning the gains for the closed-loop system C = [ 1 0 0 0 0 ; 0 1 0 0 0 ]; p = length(C(:,1)); Aa = [ A , zeros(n,p) ; -C , zeros(p,p) ]; Ba = [ B ; zeros(p,m) ]; % the ransk for the controlability rank( [ Ba Aa*Ba Aa^2*Ba Aa^3*Ba Aa^4*Ba Aa^5*Ba Aa^6*Ba ] ) P2 = [ -3 -4 -4.01 -5 -5.01 -10 -15 ]; Ka = place( Aa,Ba,P2 ); Kp = Ka(:,1:5); Ki = -Ka(:,6:7); %% Second simulation At = [ A-B*Kp , B*Ki ; -C , zeros(2,2) ]; Bt = [ zeros(5,2) ; eye(2) ]; x0 = zeros(n+2 , 1); % We simulate the increased system not (Aa,Ba) [t2,x2] = ode45(@(t,x) DiffEcus(t,x, At , Bt ), tspan, x0 ); %% Plotting figure subplot(1,2,1) plot( t , x2(:,1) ) title('second simulation') xlabel('time [s]') ylabel('y_1') grid subplot(1,2,2) plot( t , x2(:,2) ) xlabel('time [s]') ylabel('y_2') grid figure subplot(1,3,1) plot( t , y(1,:) ) xlabel('time [s]') ylabel('y_1') grid subplot(1,3,2) plot( t , y(2,:) ) title('first simulation') xlabel('time [s]') ylabel('y_2') grid subplot(1,3,3) plot( t , y(3,:) ) xlabel('time [s]') ylabel('y_3') grid Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
