Names:-Ali Nawaz Ranjha: COMSATS-Lancaster Dual Degree
Names:-Ali Nawaz Ranjha: COMSATS-Lancaster Dual Degree
Programme
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).
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
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:-
Results:Tf =
32
Tf =
50
Tf =
68
.
.
.
.
.
Tf =
356
Tf =
374
Tf =
392