You are on page 1of 28

ME5701 Mathematics for Engineering Research

Homework 3

Reinaldy Maslim

A0225239E

Given the above model of e.g a suspension system:

1. write the equations of motions

for m1,
−𝑘1 𝑥1 − 𝑐1𝑥1̇ + 𝑘2 (𝑥2 − 𝑥1 ) + 𝑐2(𝑥2̇ − 𝑥1̇ ) + 𝑓1 = 𝑚1 𝑥1̈

(𝑐1 + 𝑐2 ) (𝑘1 + 𝑘2 ) 𝑐2 𝑘2 𝑓1
− 𝑥1̇ − 𝑥1 + 𝑥2̇ + 𝑥2 + = 𝑥1̈
𝑚1 𝑚1 𝑚1 𝑚1 𝑚1

for m2,
−𝑘2 (𝑥2 − 𝑥1 ) − 𝑐2 (𝑥2̇ − 𝑥1̇ ) + 𝑓2 = 𝑚2 𝑥2̈

𝑐1 𝑘2 𝑐2 𝑘2 𝑓2
𝑥1̇ + 𝑥1 − 𝑥2̇ − 𝑥2 + = 𝑥2̈
𝑚2 𝑚2 𝑚2 𝑚2 𝑚2

2. Write the corresponding dynamical system

we now let

𝑥1 = 𝑞1 𝑥1̇ = 𝑞1̇ 𝑥1̈ = 𝑞1̈


𝑥2 = 𝑞2 𝑥2̇ = 𝑞2̇ 𝑥2̈ = 𝑞2̈
then,
−(𝑐1 +𝑐2 ) −(𝑘1 +𝑘2 ) 𝑐2 𝑘2
𝑞1̈ 𝑚1 𝑚1 𝑚1 𝑚1 𝑞1̇
𝑞̇ 1 0 0 0 𝑞
𝑥̇ = [ 1 ] 𝐴= 𝑥 = [ 1]
𝑞2̈ 𝑐2 𝑘2 −𝑐2 −𝑘2 𝑞2̇
𝑞2̇ 𝑚2 𝑚2 𝑚2 𝑚2 𝑞2
[ 0 0 1 0 ]
1/𝑚1 0
0 0 𝑓
𝐵=[ ] 𝑢 = [ 1]
0 1/𝑚2 𝑓2
0 0
0 1 0 0 0 0
𝐶=[ ] 𝐷=[ ]
0 0 0 1 0 0
𝑞1̈ 𝑞1̇
𝑞1̇ 𝑞 𝑓
𝑥̇ = 𝐴𝑥 + 𝐵𝑢, [ ] = 𝐴 [ 1] + 𝐵 [ 1 ]
𝑞2̈ 𝑞2̇ 𝑓2
𝑞2̇ 𝑞2
𝑞1̇
𝑞
𝑦 = 𝐶𝑥 + 𝐷𝑢 = 𝐶 [ 1 ]
𝑞2̇
𝑞2

3. Solve the linear dynamical system via ODE45 in Matlab

clc
clear
close all

%% Define parameters
m1 = 1.0; % m1 mass
c1 = 0.2; % c1 damping
k1 = 2.0; % k1 stiffness

m2 = 1.0; % m2 mass
c2 = 0.2; % c2 damping
k2 = 2.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[q1'',q1',q2'',q2']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) + k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution vs. time')
grid on
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')
grid on

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1'); ylabel('q1_{prime}'); title('q1 Phase
Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2'); ylabel('q2_{prime}'); title('q2 Phase
Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end

A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 0];

D=[0 0;0 0]

[v,d]=eig(A)

Output:

4. Discuss the stability of the system for different damping parameters c1 and c2

we vary c1 and c2 by setting c1=0, c2=0.2 in the first case and c1=0.2, c2=0 in the second case
case 1, c1=0, c2=0.2

clc
clear
close all

%vary c1 and c2
%first case, c1=0, c2=0.2
%second case, c1=0.2, c2=0
%third case, c1=5, c2=0.2

%check eigenval and eigenvec of A, magnitude, sign of real part, etc


%% Define parameters
m1 = 1.0; % m1 mass
c1 = 0.0; % c1 damping
k1 = 2.0; % k1 stiffness

m2 = 1.0; % m2 mass
c2 = 0.2; % c2 damping
k2 = 2.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[q1'',q1',q2'',q2']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) + k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution vs.
time')
grid on
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')
grid on

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1'); ylabel('q1_{prime}');
title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2'); ylabel('q2_{prime}');
title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end

A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 0];

D=[0 0;0 0]

[v,d]=eig(A)

Output:

case 2, c1=0.2, c2=0


clc
clear
close all

%% Define parameters
m1 = 1.0; % m1 mass
c1 = 0.2; % c1 damping
k1 = 2.0; % k1 stiffness

m2 = 1.0; % m2 mass
c2 = 0.0; % c2 damping
k2 = 2.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[q1'',q1',q2'',q2']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) + k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution vs.
time')
grid on
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')
grid on

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1'); ylabel('q1_{prime}');
title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2'); ylabel('q2_{prime}');
title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end

A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 0];

D=[0 0;0 0]

[v,d]=eig(A)

Output:

In the two cases, we observed that m1 decay faster than m2, as we can see from the eigenvalues
of A.
−𝟎. 𝟏𝟖𝟗𝟓 + 𝟐. 𝟐𝟕𝟖𝟑𝐢 −𝟎. 𝟎𝟕𝟐𝟑 + 𝟐. 𝟐𝟖𝟓𝟏𝐢
−𝟎. 𝟏𝟖𝟗𝟓 − 𝟐. 𝟐𝟕𝟖𝟑𝐢 −𝟎. 𝟎𝟕𝟐𝟑 − 𝟐. 𝟐𝟖𝟓𝟏𝐢
𝝀𝟏 = [ ] 𝝀𝟐 = [ ]
−𝟎. 𝟎𝟏𝟎𝟓 + 𝟎. 𝟖𝟕𝟒𝟕𝐢 −𝟎. 𝟎𝟐𝟕𝟕 + 𝟎. 𝟖𝟕𝟒𝟒𝐢
−𝟎. 𝟎𝟏𝟎𝟓 − 𝟎. 𝟖𝟕𝟒𝟕𝐢 −𝟎. 𝟎𝟐𝟕𝟕 − 𝟎. 𝟖𝟕𝟒𝟒𝐢
for large c’s, if either c1 or c2 is large, the system will immediately decay to zero
case 3, c1=5, c2=0.2

clc
clear
close all

%% Define parameters
m1 = 1.0; % m1 mass
c1 = 5.0; % c1 damping
k1 = 2.0; % k1 stiffness

m2 = 1.0; % m2 mass
c2 = 0.2; % c2 damping
k2 = 2.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[q1'',q1',q2'',q2']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) + k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution vs.
time')
grid on
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')
grid on

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1'); ylabel('q1_{prime}');
title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2'); ylabel('q2_{prime}');
title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end

A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 0];

D=[0 0;0 0]

[v,d]=eig(A)

Output:

5. Discuss the observability of the system assuming that you can measure q1 and q2, q1 only and
q2 only, respectively
Suppose we change the initial parameters to:
m1 = m2 = 2.0
c1 = c2 = 0.2
k1 = k2 = 1.0
then, we can get the observalibility gramian and calculate the eigenvalues.
change entries of C

first case C = [0 1 0 0;0 0 0 1]; %can measure q1 and q2

second case C= [0 1 0 0;0 0 0 0] %can measure q1 only

third case C= [0 0 0 0;0 0 0 1] %can measure q2 only

case 1, can measure both q1 and q2


clc
clear
close all

%change entries of C
%first case C = [0 1 0 0;0 0 0 1]; %can measure q1 and q2
%second case C= [0 1 0 0;0 0 0 0] %can measure q1 only
%third case C= [0 0 0 0;0 0 0 1] %can measure q2 only

%% Define parameters
m1 = 2.0; % m1 mass
c1 = 0.2; % c1 damping
k1 = 1.0; % k1 stiffness

m2 = 2.0; % m2 mass
c2 = 0.2; % c2 damping
k2 = 1.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[x'',x',y'',y']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) +
k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution
vs. time')
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1');
ylabel('q1_{prime}'); title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2');
ylabel('q2_{prime}'); title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end

%% Controllability and Observability


A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 1];

D=[0 0;0 0];

OO = obsv(A,C);
rankOO=rank(OO)

sys = ss(A,B,C,D);
Wo = gram(sys,'o')
[vo,do]=eig(Wo)
Output:
rankOO=
4
Wo =
20.0000 1.0000 30.0000 1.0000
1.0000 5.1000 1.0000 5.0000
30.0000 1.0000 50.0000 2.0000
1.0000 5.0000 2.0000 10.1000

vo =
0.7572 0.3875 -0.0248 0.5251
-0.3875 0.7572 0.5251 0.0248
-0.4680 -0.2395 -0.0401 0.8497
0.2395 -0.4680 0.8497 0.0401

do =
1.2635 0 0 0
0 2.2053 0 0
0 0 13.0666 0
0 0 0 68.6646

case 2, can measure q1 only


clc
clear
close all

%change entries of C
%first case C = [0 1 0 0;0 0 0 1]; %can measure q1 and q2
%second case C= [0 1 0 0;0 0 0 0] %can measure q1 only
%third case C= [0 0 0 0;0 0 0 1] %can measure q2 only

%% Define parameters
m1 = 2.0; % m1 mass
c1 = 0.2; % c1 damping
k1 = 1.0; % k1 stiffness

m2 = 2.0; % m2 mass
c2 = 0.2; % c2 damping
k2 = 1.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[x'',x',y'',y']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) +
k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution
vs. time')
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1');
ylabel('q1_{prime}'); title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2');
ylabel('q2_{prime}'); title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end
%% Controllability and Observability
A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 0];

D=[0 0;0 0];

OO = obsv(A,C);
rankOO=rank(OO)

sys = ss(A,B,C,D);
Wo = gram(sys,'o')
[vo,do]=eig(Wo)
Output:
rankOO=
4

Wo =

6.0938 0.4141 8.0469 0.5859


0.4141 2.1703 -0.1719 1.0352
8.0469 -0.1719 13.9063 0.5859
0.5859 1.0352 0.5859 2.9297

vo =
0.7628 0.3537 0.1073 0.5306
-0.4113 0.6981 0.5860 0.0075
-0.4824 -0.1925 -0.1201 0.8461
0.1276 -0.5920 0.7941 0.0507

do =
0.8798 0 0 0
0 1.5496 0 0
0 0 3.6841 0
0 0 0 18.9865

case 3, can measure q2 only


clc
clear
close all

%change entries of C
%first case C = [0 1 0 0;0 0 0 1]; %can measure q1 and q2
%second case C= [0 1 0 0;0 0 0 0] %can measure q1 only
%third case C= [0 0 0 0;0 0 0 1] %can measure q2 only

%% Define parameters
m1 = 2.0; % m1 mass
c1 = 0.2; % c1 damping
k1 = 1.0; % k1 stiffness

m2 = 2.0; % m2 mass
c2 = 0.2; % c2 damping
k2 = 1.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[x'',x',y'',y']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) +
k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution
vs. time')
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1');
ylabel('q1_{prime}'); title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2');
ylabel('q2_{prime}'); title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end
%% Controllability and Observability
A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 0 0 0;
0 0 0 1];

D=[0 0;0 0];

OO = obsv(A,C);
rankOO=rank(OO)
sys = ss(A,B,C,D);
Wo = gram(sys,'o')
[vo,do]=eig(Wo)

Output:
rankOO=
4

Wo =

13.9063 0.5859 21.9531 0.4141


0.5859 2.9297 1.1719 3.9648
21.9531 1.1719 36.0938 1.4141
0.4141 3.9648 1.4141 7.1703

vo =
0.7703 0.3595 -0.0614 0.5230
-0.3471 0.7859 0.5108 0.0310
-0.4716 -0.2305 -0.0174 0.8510
0.2524 -0.4472 0.8573 0.0363

do =
0.3387 0 0 0
0 0.5981 0 0
0 0 9.4741 0
0 0 0 49.6891

From the three cases, the eigenvalues of the observability gramian matrix tells us that
observability is better when q2 can be measured.

6. Discuss the controllability of the system for different damping parameters c1 and c2

case 1, c1=0.2; c2=10

clc
clear
close all

%vary c1 and c2
%first case, c1=0.2; c2=10
%second case, c1=10, c2=0.2
%third case, c1=10, c2=10
%% Define parameters
m1 = 2.0; % m1 mass
c1 = 0.2; % c1 damping
k1 = 1.0; % k1 stiffness

m2 = 2.0; % m2 mass
c2 = 10; % c2 damping
k2 = 1.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[x'',x',y'',y']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) +
k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution
vs. time')
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1');
ylabel('q1_{prime}'); title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2');
ylabel('q2_{prime}'); title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end
%% Controllability and Observability
A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 1];

D=[0 0;0 0];

CC = ctrb(A,B);
rankCC=rank(CC)

sys = ss(A,B,C,D);
Wc = gram(sys,'c')
[vc,dc]=eig(Wc)

Output:
rankCC =

Wc =

0.8496 -0.0000 0.8575 -0.1586


-0.0000 3.4142 0.1586 3.5433
0.8575 0.1586 0.8983 0.0000
-0.1586 3.5433 0.0000 3.7542

vc =

0.6980 -0.1760 -0.6939 -0.0162


0.1282 0.7094 -0.0670 0.6898
-0.6985 0.0439 -0.7141 0.0153
-0.0918 -0.6811 0.0635 0.7237

dc =

0.0124 0 0 0
0 0.0223 0 0
0 0 1.7465 0
0 0 0 7.1351

case 2, c1=10, c2=0.2


clc
clear
close all

%vary c1 and c2
%first case, c1=0.2; c2=10
%second case, c1=10, c2=0.2
%third case, c1=10, c2=10
%% Define parameters
m1 = 2.0; % m1 mass
c1 = 10; % c1 damping
k1 = 1.0; % k1 stiffness

m2 = 2.0; % m2 mass
c2 = 0.2; % c2 damping
k2 = 1.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[x'',x',y'',y']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) +
k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution
vs. time')
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1');
ylabel('q1_{prime}'); title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2');
ylabel('q2_{prime}'); title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end
%% Controllability and Observability
A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 1];

D=[0 0;0 0];

CC = ctrb(A,B);
rankCC=rank(CC)

sys = ss(A,B,C,D);
Wc = gram(sys,'c')
[vc,dc]=eig(Wc)

Output:

rankCC =

Wc =

0.0368 0.0000 0.0252 0.1201


0.0000 0.1240 -0.1201 0.1985
0.0252 -0.1201 0.6746 0.0000
0.1201 0.1985 0.0000 1.5718

vc =

0.9743 0.2075 0.0441 0.0753


0.2010 -0.9514 -0.1916 0.1334
-0.0007 -0.1996 0.9798 -0.0151
-0.1014 0.1096 0.0375 0.9881

dc =

0.0243 0 0 0
0 0.0760 0 0
0 0 0.6993 0
0 0 0 1.6078

case 3, c1=10, c2=10

clc
clear
close all

%vary c1 and c2
%first case, c1=0.2; c2=10
%second case, c1=10, c2=0.2
%third case, c1=10, c2=10
%% Define parameters
m1 = 2.0; % m1 mass
c1 = 10; % c1 damping
k1 = 1.0; % k1 stiffness

m2 = 2.0; % m2 mass
c2 = 10; % c2 damping
k2 = 1.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[x'',x',y'',y']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) +
k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution
vs. time')
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1');
ylabel('q1_{prime}'); title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2');
ylabel('q2_{prime}'); title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end
%% Controllability and Observability
A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 1];

D=[0 0;0 0];

CC = ctrb(A,B);
rankCC=rank(CC)
sys = ss(A,B,C,D);
Wc = gram(sys,'c')
[vc,dc]=eig(Wc)

Output:
rankCC =

Wc =

0.0250 -0.0000 0.0250 -0.0000


-0.0000 0.1000 -0.0000 0.1500
0.0250 -0.0000 0.0500 0.0000
-0.0000 0.1500 0.0000 0.2500

vc =

-0.0000 0.8507 0.5257 -0.0000


0.8507 0.0000 -0.0000 0.5257
0.0000 -0.5257 0.8507 0.0000
-0.5257 -0.0000 0.0000 0.8507

dc =

0.0073 0 0 0
0 0.0095 0 0
0 0 0.0655 0
0 0 0 0.3427

From the three cases, based on the eigenvalues of the controllability gramian matrix and
the plots, we can conclude that a larger value of c1 has adverse effects on the
controllability of the system compared to a large value of c2, in which the system still
oscillates. For large values of c1 and c2, the system is overdamped and decay to zero
immediately.
7. What happens to the controllability of the system when we apply the input u on the first
mass only?
The system is still controllable, with rank of CC=4, however the degree of controllability
decreased significantly as reflected from the eigenvalues of the controllability gramian
matrix and the zero columns in CC.
We change the entry in the matrix B.
clc
clear
close all

%% Define parameters
m1 = 2.0; % m1 mass
c1 = 0.2; % c1 damping
k1 = 1.0; % k1 stiffness

m2 = 2.0; % m2 mass
c2 = 0.2; % c2 damping
k2 = 1.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[x'',x',y'',y']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) + k2/m1*y(4) +
exp(-(t - 15)^16 /1e10) * sin(8*pi*t); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1'); title('Solution
vs. time')
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1');
ylabel('q1_{prime}'); title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2');
ylabel('q2_{prime}'); title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end
%% Controllability and Observability
A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 0;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 1];

D=[0 0;0 0]

CC = ctrb(A,B)
OO = obsv(A,C)
rank(CC)
rank(OO)
sys = ss(A,B,C,D);
Wc = gram(sys,'c')
[vc,dc]=eig(Wc)
Wo = gram(sys,'o')
[vo,do]=eig(Wo)
%[b,a] = ss2tf(A,B,C,D)
systf=tf(sys);
figure()
subplot(2,1,1)
step(systf)
subplot(2,1,2)
impulse(systf)

Output:
ans =

4
Wc =

0.5078 -0.0000 0.2539 -0.0977


-0.0000 1.5234 0.0977 2.0117
0.2539 0.0977 0.7422 -0.0000
-0.0977 2.0117 -0.0000 3.4766

vc =

-0.0710 0.8430 -0.5328 -0.0189


0.8384 0.0034 -0.1250 0.5306
-0.1295 -0.5373 -0.8333 0.0118
-0.5247 0.0241 0.0780 0.8473

dc =

0.2492 0 0 0
0 0.3432 0 0
0 0 0.9192 0
0 0 0 4.7384

8. Write the transfer function of the system and its impulse response in Matlab
clc
clear
close all

%% Define parameters
m1 = 1.0; % m1 mass
c1 = 0.2; % c1 damping
k1 = 2.0; % k1 stiffness

m2 = 1.0; % m2 mass
c2 = 0.2; % c2 damping
k2 = 2.0; % k2 stiffness

T0 = 0; % initial time
TN = 50; % final time
dt = 0.01; % time-step
tspan = T0:dt:TN; % time set

x0_prime = 0; % initial condition for q1_prime


x0 = 1; % initial condition for q1
y0_prime = 0; % initial condition for q2_prime
y0 = 1; % initial condition for q2

Y0=[x0_prime x0 y0_prime y0];


options = odeset('RelTol',1e-12,'AbsTol',1e-12);

%q1_prime=y(1)
%q1=y(2)
%q2_prime=y(3)
%q2=y(4)

%[x'',x',y'',y']
%% Construct the right-hand side
rhs_mck = @(t,y)[
(-(c1+c2)/m1)*y(1) - (k1+k2)/m1*y(2) + c2/m1*y(3) +
k2/m1*y(4); ...
y(1); ...
c2/m2*y(1) + k2/m2*y(2) - c2/m2*y(3) - k2/m2*y(4);...
y(3);...
];
%% Solve the system via the ODE package
[t,sol] = ode45(rhs_mck,tspan,Y0,options);
q1_s = sol(:,2);
q2_s = sol(:,4);
%% Plot results
figure()
subplot(2,1,1); plot(t,q1_s) ; xlabel('t'); ylabel('q_1');
title('Solution vs. time')
subplot(2,1,2); plot(t,q2_s) ; xlabel('t'); ylabel('q_2')

figure()
for ic = 1 : 5
x0_prime = ic;
x0 = 0;
y0_prime=ic;
y0 = 0;

%% Solve the system via the ODE package


[t,sol] = ode45(rhs_mck,tspan,[x0_prime x0 y0_prime
y0],options);
q1_prime = sol(:,1);
q1_s = sol(:,2);
q2_prime = sol(:,3);
q2_s = sol(:,4);

%% Plot results
subplot(2,1,1);plot(q1_s,q1_prime); xlabel('q1');
ylabel('q1_{prime}'); title('q1 Phase Portrait')
plot(q1_s(1) ,q1_prime(1) ,'ob')
plot(q1_s(end),q1_prime(end),'sr')
hold on
subplot(2,1,2);plot(q2_s,q2_prime); xlabel('q2');
ylabel('q2_{prime}'); title('q2 Phase Portrait')
plot(q2_s(1) ,q2_prime(1) ,'ob')
plot(q2_s(end),q2_prime(end),'sr')
hold on
end
%% Controllability and Observability
A = [ ...
(-(c1+c2)/m1), -(k1+k2)/m1, c2/m1, k2/m1; ...
1, 0, 0, 0; ...
c2/m2, k2/m2, -c2/m2, -k2/m2;...
0, 0, 1, 0;...
];

B = [ ...
1/m1, 0; ...
0, 0;...
0, 1/m2;...
0, 0;...
];

C = [0 1 0 0;
0 0 0 1];
D=[0 0;0 0]

CC = ctrb(A,B)
OO = obsv(A,C)
rank(CC)
rank(OO)
sys = ss(A,B,C,D);
Wc = gram(sys,'c')
[vc,dc]=eig(Wc)
Wo = gram(sys,'o')
[vo,do]=eig(Wo)
%[b,a] = ss2tf(A,B,C,D)
systf=tf(sys)
figure()
subplot(2,1,1)
step(systf)
subplot(2,1,2)
impulse(systf)

systf =
From input 1 to output...

s^2 + 0.2 s + 2
1: ------------------------------------
s^4 + 0.6 s^3 + 6.04 s^2 + 0.8 s + 4

0.2 s + 2
2: ------------------------------------
s^4 + 0.6 s^3 + 6.04 s^2 + 0.8 s + 4

From input 2 to output...


0.2 s + 2
1: ------------------------------------
s^4 + 0.6 s^3 + 6.04 s^2 + 0.8 s + 4

s^2 + 0.4 s + 4
2: ------------------------------------
s^4 + 0.6 s^3 + 6.04 s^2 + 0.8 s + 4

Continuous-time transfer function.

You might also like