You are on page 1of 8

COMSATS-Lancaster Dual Degree

Programme

Names:-Ali Nawaz Ranjha


Registeration # DDP-FA10-BTE-008
Control Systems Lab

Lab Session 1:Q1. Explore magic() command of MATLAB. Try A = magic(5), record your output and
explain.
Q2. Consider two polynomials p ( s)= s2+2s+a and q (s)=s+1. Using MATLAB, find
p(s)*q(s)
Roots of p(s) and q(s)
p(-1) and q(6)
Write code and record output.
Q3. Use MATLAB to find partial fraction of the following
B(s) /A(s)= 2s3+5s2+3s+6 / s3+6s2+11s+6
B(s) /A(s )=s2+2s+3 / (s+1)3
Q4. Use MATLAB to generate the first 100 terms in the sequence a(n) define
recursively by a(n+1)= P*a(n)* (1-a (n ))
with p=2.9 and a(1) = 0.5.
Q5. Use for or while loop to convert degrees Fahrenheit to degrees Celsius using the
following equation
Tf =9/5 Tc+32
Use any starting temperature, increment and ending temperature (example: starting
temperature=0, increment=10, ending temperature = 200).

Q1(ans.):The command magic creates a square matrix which


is less than the square of number entered within the
round brackets of magic command.
Syntax:magic(5)

Results:-

ans =
17
23
4
10
11

24 1 8 15
5 7 14 16
6 13 20 22
12 19 21 3
18 25 2 9

Q2(ans.):a=input('enter the value of a=');


% writing the co-efficients of p in
of matrix
p=[1 2 a];
% writing the co-efficients of q in
of matrix
q=[0 1 1];
r1=p.*q
r2=roots(p)
r3=roots(q)
% evaluating the above polynomial p
r4=polyval(p,-1)
% evaluating the above polynomial q
r5=polyval(q,6)

Results:enter the value of a=1


r1 =

the form
the form

at -1
at 6

r2 =
-1
-1
r3 =
-1
r4 =
0
r5 =
7

Q3(ans.):b=[2 5 3 6]
a=[1 6 11 6]
[r,p,k] = residue(b,a)

Results:b =

11

a =

r =
-6.0000
-4.0000
3.0000
p =
-3.0000
-2.0000
-1.0000
k =
2

(ii).
b=[1 2 3]
a=[1 3 3 1]
[r,p,k] = residue(b,a)

Results:b=
1
a=

r=
1.0000
0.0000
2.0000
p=
-1.0000
-1.0000
-1.0000
k=
[]
Q4(ans.):p=2.9;
a(1)=0.5;
for n=1:100
a(n+1)=p.*a(n).*(1-a(n))
end

Results:-

0.5000 0.7250 0.5782 0.7073 0.6004 0.6958 0.6139


0.6874. . . . . . . . . . 0.6552 0.6552 0.6552 0.6552 0.6552
Q5(ans.):for Tc = 0:10:200
Tf=9/5.*Tc+32
end

Results:Tf =
32
Tf =
50
Tf =
68
.
.
.
.
.
Tf =
356

Tf =
374
Tf =
392

You might also like