0% found this document useful (0 votes)
3 views9 pages

FCPS Assignment-1 Solution

The document provides an overview of using Matlab for basic matrix operations and system modeling, specifically focusing on the Lorenz attractor. It includes instructions for accessing Matlab online, performing matrix calculations, and solving differential equations. Additionally, it contains multiple-choice questions related to cyber-physical systems and Matlab programming tasks.

Uploaded by

madhes14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

FCPS Assignment-1 Solution

The document provides an overview of using Matlab for basic matrix operations and system modeling, specifically focusing on the Lorenz attractor. It includes instructions for accessing Matlab online, performing matrix calculations, and solving differential equations. Additionally, it contains multiple-choice questions related to cyber-physical systems and Matlab programming tasks.

Uploaded by

madhes14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

NPTEL Online Certification Courses Indian Institute

of Technology Kharagpur

Foundations of Cyber-Physical Systems


Assignment- Week 1
TYPE OF QUESTION: MCQ/MSQ

Matlab Basics

 How to use Online Matlab?


1. Go to the link: https://matlab.mathworks.com/
2. Login with your email ID to Mathworks account. If your institute has Matlab license, you can
login with your institute ID.

3. Click on the ‘New’ button on left corner of menu bar to create a new script and save it
with ‘.m’ extension.

4. Click on the ‘Run’ button (or F5) to execute the script

5. Use ‘help’ followed by Matlab’s in-built function name to know about the function
description. For example ‘help ode45’
NPTEL Online Certification Courses Indian Institute
of Technology Kharagpur

 Basic matrix operations in Matlab


% a 3x3 matrix
A = [1 2 3;
3 1 2;
5 0 4];
% a 3x2 matrix
B = [1 2;
3 4;
5 6];
disp('Determinant of A')
disp(det(A))
disp('Inverse of A')
disp(inv(A))
disp('Transpose of A')
disp(A') % Or disp(transpose(A))
disp('Rank of A')
rank(A)
disp('Eigen values of A')
eig(A)
disp('Adjoint of A')
adjoint(A)
disp('Matrix multiplication (AxB)')
disp(A*B)

Output:
Determinant of A
-15.0000

Inverse of A
-0.2667 0.5333 -0.0667
0.1333 0.7333 -0.4667
0.3333 -0.6667 0.3333

Transpose of A
1 3 5
2 1 0
3 2 4

Rank of A

ans =

Eigen values of A
NPTEL Online Certification Courses Indian Institute
of Technology Kharagpur

ans =

7.3544
-2.2577
0.9034

Adjoint of A

ans =

4.0000 -8.0000 1.0000


-2.0000 -11.0000 7.0000
-5.0000 10.0000 -5.0000

Matrix multiplication (AxB)


22 28
16 22
25 34

 Example of system modeling using Matlab: Lorenz Attractor

Lorenz model is a system of 3 non-linear ordinary differential equations that relate the
properties of a two-dimensional fluid layer uniformly warmed from below and cooled from
above:

𝑥̇ = 𝜎(𝑦 − 𝑥)

𝑦̇ = 𝑥(𝜌 − 𝑧) − 𝑦

𝑧̇ = 𝑥𝑦 − 𝛽𝑧

Here, 𝑥 ∝ the rate of convection, 𝑦 ∝ the horizontal temperature variation, and 𝑧 ∝ the
vertical temperature variation. The parameters 𝜎, 𝜌, and 𝛽 are proportional to the Prandtl
number, Reyleigh number, and certain physical dimension of the layer itself respectively
(all are assumed to be positive).

Considering 𝜎 = 10, 𝛽 = 8/3, 𝜌 = 28, and the initial values of (𝑥, 𝑦, 𝑧) = (1,1,1), the
following Matlab code simulate Lorenz model over a time window of 100 units.
NPTEL Online Certification Courses Indian Institute
of Technology Kharagpur

sigma = 10;
beta = 8/3;
rho = 28;
% Inline function definition for Lorenz model
f = @(t,a) [-sigma*a(1) + sigma*a(2); rho*a(1) - a(2) -
a(1)*a(3); -beta*a(3) + a(1)*a(2)];
% Solving ODE using Runge-Kutta 4th/5th order ODE solver
[t,a] = ode45(f,[0 100],[1 1 1]);
% plotting in 3 dimensions
plot3(a(:,1),a(:,2),a(:,3))
xlabel(‘x’);
ylabel(‘y’);
zlabel(‘z’);
NPTEL Online Certification Courses Indian Institute
of Technology Kharagpur

Number of questions: 1 Total mark: 2 X 1 = 2

Programming Questions-NEUMERIC Type-Equal Answer


Question 1
1 2 3
Find the determinant of the co-factor matrix of 𝐴 = [3 1 2] using matlab.
5 0 4

Correct answer: 225

Detailed Solution:

𝑎𝑑𝑗(𝐴)
Adjoint matrix adj(A)= transpose of co-factor matrix and 𝐴−1 = |𝐴|

Since, determinant of a square matrix is same as determinatnt of its transpose, determinant of co-factor
matrix of A is det(det(A)*inv(A))=225

Number of questions: 5 Total mark: 5 X 1 = 5

Objective Questions-MCQ type (True/False Answer)


Question 2

In data-driven predictive control using regression trees the regions of controllable variables are
predicted.
a. True
b. False

Correct Answer: a. True

Question 3

Detectors in a cyber-physical systems are usually used in order to detect if there is a requirement for
better cost optimization in control strategy.
a. True
b. False

Correct Answer: b. False


NPTEL Online Certification Courses Indian Institute
of Technology Kharagpur

Question 4

Using SUMO as a network simulator with a mobility simulator like Omnet++ we can simulate a vehicle
platoon
a. True
b. False

Correct Answer: b. False

Question 5

A Hardware-in-loop helps us understand a real-time CPS behavior.


a. True
b. False

Correct Answer: a. True

Question 6

Robot Operating System can manage low-level device control in a lab scale autonomous vehicle setup.
a. True
b. False

Correct Answer: a. True


NPTEL Online Certification Courses Indian Institute
of Technology Kharagpur

Number of questions: 6 Total mark: 3 X 6 = 18


Programming Questions-MCQ Type

Question 7

The van der Pol equation is a second-order ODE as follows:


𝑦̇1 = 𝑦2
𝑦̇ 2 = 𝜇(1 − 𝑦12 )𝑦2 − 𝑦1

The following code evaluates the van der Pol ODEs for 𝜇 = 1 and intial value 𝑦1 = 2, 𝑦2 = 0 for 0 to 20
units of time.

function dydt = vdp1(t,y)


% y1 = y(1); y2 = y(2)
dydt = [y(2); _______*y(2)-y(1)];

[t,y] = ode45(___, _______, _______);


plot(t,y(:,1),'-o',t,y(:,2),'-o')
title('Solution of van der Pol Equation (\mu = 1) with ODE45');
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')

Complete the blanks from the following options:


(a) (1-y(1)^2), @dydt,[0 20],[2; 0]
(b) (1-y(1)^2), @vdp1,[2; 0] ,[0 20]
(c) (1-y(1)^2), @vdp1,[0 20],[2; 0]
(d) (1-y(1)^2), dydt,[2; 0] ,[0 20]

Correct answer: c

Detail Explanation:

𝑑𝑦 𝑦̇ 𝑦2
Since, 𝜇 = 1, = [ 1 ] = [(1 2 )𝑦 ]
𝑑𝑡 𝑦̇ 2 − 𝑦1 2 − 𝑦1
The definition of Matlab’s ode45 function is ode45(ODEFUN,TSPAN,Y0) where ODEFUN(T,Y) is a
function handle, TSPAN is the time duration and Y0 is the initial condition. Type ‘help ode45’ in Matlab
command window to know more about this function’s details.
NPTEL Online Certification Courses Indian Institute
of Technology Kharagpur

Question 8

Find out using Matlab, which one of the following matrices are Schur stable.
1 2
1. 𝐴1 = [ ]
−1 3
−1 − 0.2
2. 𝐴2 = [ ]
1 0.3
−1 0.2
3. 𝐴3 = [ ]
0.1 0.3
1 2
4. 𝐴4 = [ ]
−1 3
1 − 0.2
5. 𝐴5 = [ ]
−1 0.3

Correct Answer: 2,3

Detailed Answer:
If all eigenvalues of a matrix A have norm strictly less than one; i.e. the spectral radius of A is less than
one, then the matrix A is Schur stable.

norm(max(eig(A1)),Inf) = 2.2361
norm(max(eig(A2)),Inf) = 0.1217
norm(max(eig(A3)),Inf) = 0. 3152
norm(max(eig(A4)),Inf) = 2.2361
norm(max(eig(A5)),Inf) = 1.2179

Question 9

Find out which of the matrices below are orthogonal using Matlab. We call a matrix 𝐴 orthogonal when
𝐴 ∗ 𝐴𝑇 = 𝑖𝑑𝑒𝑛𝑡𝑖𝑡𝑦.

2 4 6
1. 𝐴1 = [ 1 3 − 5 ]
−2 7 9
−1 0
2. 𝐴2 = [ ]
0 −1
2 3
3. 𝐴3 = [ ]
1 2
2 −2 1
4. 𝐴4 = [ 1 2 2 ]
2 1 −2
−0.6059 0.7956
5. 𝐴5 = [ ]
0.7956 0.6059

Correct Answer: 2, 5
NPTEL Online Certification Courses Indian Institute
of Technology Kharagpur

Question 10

If all eigenvalues of a matrix A have norm strictly less than one; i.e. the spectral radius of A is less than
one, then the matrix A is Schur stable. Fill in the blank such that the following Matlab code snippet
checks whether matrix A is schur stable and returns 𝑡𝑟𝑢𝑒 or 𝑓𝑎𝑙𝑠𝑒. Note that Matlab function
𝑛𝑜𝑟𝑚(𝑋, 𝐼𝑛𝑓) returns the infinity norm of a vector X i.e. ||𝑋||∞

norm(max(_____),Inf)<_

a. poles(A),0
b. eig(A), 0
c. eig(A),1
d. rank(A),rank(AT)

Correct Answer: (c) eig(A),1

Question 11

Write the Matlab command to find the determinant of the co-factor matrix of 𝐴

a. det(transpose(det(A)*inv(A)))
b. det(A)*inv(transpose(A))
c. transpose(det(transpose(A))*inv(A))
d. -det(A)*inv(A)

Correct Answer: (a) det(transpose(det(A)*inv(A)))

Detailed Solution:

𝑎𝑑𝑗(𝐴)
Adjoint matrix adj(A)= transpose of co-factor matrix and 𝐴−1 = |𝐴|
Therefore, transpose of co-factor matrix = adjoint matrix = 𝐴−1 × |A|
And, determinant of co-factor matrix = det(transpose(det(A)*inv(A)))

Question 12

max() function is used to find ___ _ ___ and abs() function is used to find __ __ ___.

a. Maximum in an array, absolute value of a negative number


b. Maximum in each column of a matrix, modulus value of a number
c. Maximum in a row matrix, distance of a number from zero along the number line
d. Maximum in a column matrix, absolute value of an integer

Correct Answer: a,b,c,d

You might also like