Matlab 1
Matlab 1
Submitted to:
Engr. Johaimen M. Omar
Submitted by:
Rauda Nano Antol
1.1 OBJECTIVES
To learn to use MATLAB to (1) generate polynomials, (2) manipulate polynomials, (3) generate transfer
functions, (4) manipulate transfer functions, and (5) perform partial-fraction expansions.
1.3 PRELAB
1. Calculate the following by hand or with a calculator:
a. The roots of 𝑃1 = 𝑠6 + 7𝑠5 + 2𝑠4 + 9𝑠3 + 10𝑠2 + 12𝑠 + 15
b. The roots of 𝑃2 = 𝑠6 + 9𝑠5 + 8𝑠4 + 9𝑠3 + 12𝑠2 + 15𝑠 + 20
c. 𝑃3 = 𝑃1 + 𝑃2 ; 𝑃4 = 𝑃1 − 𝑃2 ; 𝑃5 = 𝑃1 𝑃2
Solution 1a:
Irrational and complex roots must be expected. Since higher order polynomials are involved, the better
way to find roots with a calculator is the Newton’s method by which selecting random real or complex
numbers and then iterating until each exact root is extracted. Although this is a trial-and-error method, it
is more effective and faster than other manual methods. The Newton’s method is given by
𝑃 (𝑠𝑛 )
𝑠𝑛 = 𝑠𝑛+1 −
𝑃 (𝑠𝑛 )
Knowing that
𝑃1 = 𝑠6 + 7𝑠5 + 2𝑠4 + 9𝑠3 + 10𝑠2 + 12𝑠 + 15 and
𝑃1 = 6𝑠5 + 35𝑠4 + 8𝑠3 + 27𝑠2 + 20𝑠 + 12
With the calculator, use ANS as iteration and compute
ANS6 + 7(ANS5 ) + 2(ANS4 ) + 9(ANS3 ) + 10(ANS2 ) + 12(ANS) + 15
𝑠 = ANS −
6(ANS5 ) + 35(ANS4 ) + 8(ANS3 ) + 27(ANS2 ) + 20(ANS) + 12
For 1st root, select ANS = −6, For 2nd root, select ANS = −1,
𝑠 = −9.1597 𝑠 = −1
𝑠 = −8.1416 𝑠 = −1
𝑠 = −7.4278 ⋮
𝑠 = −7.0236 𝑠 = −1
𝑠 = −6.8876
𝑠 = −6.8733
𝑠 = −6.8731
𝑠 = −6.8731
⋮
𝑠 = −6.8731
For 3rd and 4th roots, select ANS = −1 ± 𝑗, For 5th and 6th roots, select ANS = 1 ± 𝑗,
𝑠 = −0.7015 ± 𝑗0.7913 𝑠 = 0.8126 ± 𝑗1.0110
𝑠 = −0.2717 ± 𝑗0.6783 𝑠 = 0.7532 ± 𝑗1.0718
𝑠 = −0.3984 ± 𝑗1.5237 𝑠 = 0.7634 ± 𝑗1.0826
𝑠 = −0.3390 ± 𝑗1.2694 𝑠 = 0.7632 ± 𝑗1.0822
𝑠 = −0.3185 ± 𝑗1.1181 𝑠 = 0.7632 ± 𝑗1.0822
𝑠 = −0.3242 ± 𝑗1.0700 𝑠⋮
𝑠 = −0.3266 ± 𝑗1.0667 𝑠 = 0.7632 ± 𝑗1.0822
𝑠 = −0.3266 ± 𝑗1.0667
⋮
𝑠 = −0.3266 ± 𝑗1.0667
Thus, the roots are
𝑠 = −6.8731
𝑠 = −1
𝑠 = −0.3266 − 𝑗1.0667
𝑠 = −0.3266 + 𝑗1.0667
𝑠 = 0.7632 − 𝑗1.0822
𝑠 = 0.7632 + 𝑗1.0822
Solution 1b:
Knowing that
𝑃2 = 𝑠6 + 9𝑠5 + 8𝑠4 + 9𝑠3 + 12𝑠2 + 15𝑠 + 20 and
𝑃2 = 6𝑠5 + 45𝑠4 + 32𝑠3 + 27𝑠2 + 24𝑠 + 15
With the calculator, compute
ANS6 + 9(ANS5 ) + 8(ANS4 ) + 9(ANS3 ) + 12(ANS2 ) + 15(ANS) + 20
𝑠 = ANS −
6(ANS5 ) + 45(ANS4 ) + 32(ANS3 ) + 27(ANS2 ) + 24(ANS) + 15
For 1st root, select ANS = −8, For 2nd root, select ANS = −1,
𝑠 = −8.1453 𝑠 = −1.3200
𝑠 = −8.1331 𝑠 = −1.2323
𝑠 = −8.1330 𝑠 = −1.2186
𝑠 = −8.1330 𝑠 = −1.2183
⋮ 𝑠 = −1.2183
𝑠 = −8.1330 ⋮
𝑠 = −1.2183
For 3rd and 4th roots, select ANS = −1 ± 𝑗, For 5th and 6th roots, select ANS = 1 ± 𝑗,
𝑠 = −0.7168 ± 𝑗0.8399 𝑠 = 0.8009 ± 𝑗0.9542
𝑠 = −0.3863 ± 𝑗0.9486 𝑠 = 0.7081 ± 𝑗0.9716
𝑠 = −0.5789 ± 𝑗1.0392 𝑠 = 0.6990 ± 𝑗0.9878
𝑠 = −0.5239 ± 𝑗1.0450 𝑠 = 0.6996 ± 𝑗0.9880
𝑠 = −0.5240 ± 𝑗1.0501 𝑠 = 0.6996 ± 𝑗0.9880
𝑠 = −0.5240 ± 𝑗1.0501 ⋮
⋮ 𝑠 = 0.6996 ± 𝑗0.9880
𝑠 = −0.5240 ± 𝑗1.0501 −
Thus, the roots are
𝑠 = −8.1330
𝑠 = −1.2183
𝑠 = −0.5240 − 𝑗1.0501
𝑠 = −0.5240 + 𝑗1.0501
𝑠 = 0.6996 − 𝑗0.9880
𝑠 = 0.6996 + 𝑗0.9880
Solution 1c:
𝑃 3 = 𝑃1 + 𝑃 2
𝑃3 = 𝑠6 + 7𝑠5 + 2𝑠4 + 9𝑠3 + 10𝑠2 + 12𝑠 + 15 + 𝑠6 + 9𝑠5 + 8𝑠4 + 9𝑠3 + 12𝑠2 + 15𝑠 + 20
𝑃3 = 2𝑠6 + 16𝑠5 + 10𝑠4 + 18𝑠3 + 22𝑠2 + 27𝑠 + 35
𝑃 4 = 𝑃1 − 𝑃 2
𝑃4 = 𝑠6 + 7𝑠5 + 2𝑠4 + 9𝑠3 + 10𝑠2 + 12𝑠 + 15 − 𝑠6 + 9𝑠5 + 8𝑠4 + 9𝑠3 + 12𝑠2 + 15𝑠 + 20
𝑃4 = −2𝑠5 − 6𝑠4 − 2𝑠2 − 3𝑠 − 5
Multiplying two factors with such higher order polynomial can be done by Pascal triangle to neaten the
solution.
𝑃5 = 𝑃1 𝑃2
𝑃5 = 𝑠6 + 7𝑠5 + 2𝑠4 + 9𝑠3 + 10𝑠2 + 12𝑠 + 15 𝑠6 + 9𝑠5 + 8𝑠4 + 9𝑠3 + 12𝑠2 + 15𝑠 + 20
𝑃5 = 𝑠12 + (9 + 7)𝑠11 + (8 + 63 + 2)𝑠10 + (9 + 56 + 18 + 9)𝑠9 + (12 + 63 + 16 + 81)𝑠8 + (15 + 84
+ 18 + 72 + 90 + 12)𝑠7 + (20 + 105 + 24 + 81 + 80 + 108 + 15)𝑠6 + (140 + 30
+ 108 + 90 + 96 + 135)𝑠5 + (40 + 135 + 120 + 108 + 120)𝑠4 + (180 + 150 + 144
+ 135)𝑠3 + (200 + 180 + 180)𝑠2 + (240 + 225)𝑠 + 300
𝑃5 = 𝑠12 + 16𝑠11 + 73𝑠10 + 92𝑠9 + 182𝑠8 + 291𝑠7 + 433𝑠6 + 599𝑠5 + 523𝑠4 + 609𝑠3 + 560𝑠2 + 465𝑠
+ 300
Solution 3a:
20(𝑠 + 2)(𝑠 + 3)(𝑠 + 6)(𝑠 + 8)
𝐺1 (𝑠) =
𝑠(𝑠 + 7)(𝑠 + 9)(𝑠 + 10)(𝑠 + 15)
20(𝑠2 + 5𝑠 + 6)(𝑠2 + 14𝑠 + 48)
𝐺1 (𝑠) = 2
𝑠(𝑠 + 16𝑠 + 63)(𝑠2 + 25𝑠 + 150)
20(𝑠4 + 19𝑠3 + 124𝑠2 + 324𝑠 + 288)
𝐺1 (𝑠) = 4
𝑠(𝑠 + 41𝑠3 + 613𝑠2 + 3975𝑠 + 9450)
20𝑠4 + 380𝑠3 + 2480𝑠2 + 6480𝑠 + 5760
𝐺1 (𝑠) = 5
𝑠 + 41𝑠4 + 613𝑠3 + 3975𝑠2 + 9450𝑠
Solution 3b:
𝑠4 + 17𝑠3 + 99𝑠2 + 223𝑠 + 140
𝐺2 (𝑠) =
𝑠5 + 32𝑠4 + 363𝑠3 + 2092𝑠2 + 5052𝑠 + 4320
Let us distinguish the numerator n and denominator d for factoring.
For numerator, the remainder theorem can be tested where the remainder must be zero. Recall the rational
root theorem where the factors of constant term can be possible to get the roots. Knowing that factors of
±140 are ±1, ±2, ±4, ±5, ±7, ±10, ±14, ±20, ±28, ±35 and ±70. With the calculator, compute
𝑅 = ANS4 + 17(ANS3 ) + 99(ANS2 ) + 223(ANS) + 140
For the roots 𝑠 = {−7, −5, −4, −1}, all 𝑅 = 0.
Solution 3c:
Polynomial form of 𝐺3 (𝑠):
𝐺3 (𝑠) = 𝐺1 (𝑠) + 𝐺2 (𝑠)
20𝑠4 + 380𝑠3 + 2480𝑠2 + 6480𝑠 + 5760 𝑠5 + 32𝑠4 + 363𝑠3 + 2092𝑠2 + 5052𝑠 + 4320
+ 𝑠4 + 17𝑠3 + 99𝑠2 + 223𝑠 + 140 𝑠5 + 41𝑠4 + 613𝑠3 + 3975𝑠2 + 9450𝑠
𝐺3 (𝑠) =
𝑠5 + 41𝑠4 + 613𝑠3 + 3975𝑠2 + 9450𝑠 𝑠5 + 32𝑠4 + 363𝑠3 + 2092𝑠2 + 5052𝑠 + 4320
Factored form of 𝐺4 (𝑠): Whereas LCD is used in the denominator, Newton’s method is used in the
numerator. With the calculator, compute
19(ANS9 ) + 962(ANS8 ) + 20 491(ANS7 ) + 246 942(ANS6 ) + 1 862 365(ANS5 )
+ 9 034 266(ANS4 ) + 27 909 805(ANS3 ) + 52 836 630(ANS2 )
+ 55 770 120(ANS) + 24 883 200
𝑠 = ANS −
171(ANS ) + 7696(ANS7 ) + 143 437(ANS6 ) + 1 481 652(ANS5 ) + 9 311 825(ANS4 )
8
+ 36 137 064(ANS3 ) + 83 729 415(ANS2 ) + 105 673 260(ANS) + 55 770 120
For 1st root, select ANS = −17, For 2nd root, select ANS = −8,
𝑠 = −16.8330 𝑠 = −8.0008
𝑠 = −16.8140 𝑠 = −8.0008
𝑠 = −16.8138 𝑠⋮
𝑠 = −16.8138 𝑠 = −8.0008
𝑠⋮
𝑠 = −16.8138
For 3rd root, select ANS = −6, For 4th root, select ANS = −3,
𝑠 = −5.9971 𝑠 = −3.3092
𝑠 = −5.9971 𝑠 = −3.2537
𝑠⋮ 𝑠 = −3.2517
𝑠 = −5.9971 𝑠 = −3.2517
𝑠 ⋮
𝑠 = −3.2517
For 5th root, select ANS = −1, For 6th and 7th roots, select ANS = −5 ± 𝑗5,
𝑠 = −1.2545 𝑠 = −5.4680 ± 𝑗4.9810
𝑠 = −1.4182 𝑠 = −5.3160 ± 𝑗5.1735
𝑠 = −1.4853 𝑠 = −5.3680 ± 𝑗5.1588
𝑠 = −1.4953 𝑠 = −5.3690 ± 𝑗5.1617
𝑠 = −1.4955 𝑠 = −5.3690 ± 𝑗5.1617
𝑠 = −1.4955 𝑠⋮
𝑠⋮ 𝑠 = −5.3690 ± 𝑗5.1617
𝑠 = −1.4955
For 8th and 9th roots, select ANS = −2 ± 𝑗2,
𝑠 = −2.1449 ± 𝑗1.6425
𝑠 = −2.2100 ± 𝑗1.3670
𝑠 = −2.2054 ± 𝑗1.1991
𝑠 = −2.1739 ± 𝑗1.1488
𝑠 = −2.1673 ± 𝑗1.1490
𝑠 = −2.1674 ± 𝑗1.1491
𝑠 = −2.1674 ± 𝑗1.1491
𝑠⋮
𝑠 = −2.1674 ± 𝑗1.1491
Because of this “gain” which can be found the coefficient of the leading order of polynomial in the
numerator, that is 19, therefore
19(𝑠 + 16.8138)(𝑠 + 8.0008)(𝑠 + 5.9971)(𝑠 + 3.2517)(𝑠 + 1.4955)
(𝑠 + 2.1674 + 𝑗1.1491)(𝑠 + 2.1674 − 𝑗1.1491)
(𝑠 + 5.3690 + 𝑗5.1617)(𝑠 + 5.3690 − 𝑗5.1617)
𝐺4 (𝑠) =
𝑠(𝑠 + 7)(𝑠 + 9)(𝑠 + 10)(𝑠 + 15)(𝑠 + 16.7851)(𝑠2 + 4.0966𝑠 + 4.4681)
(𝑠2 + 11.1182𝑠 + 57.6004)
4. Calculate by hand or with calculator the partial-fraction expansion of the following transfer functions:
5(𝑠 + 2)
a. 𝐺6 (𝑠) = 2
𝑠(𝑠 + 8𝑠 + 15)
5(𝑠 + 2)
b. 𝐺7 (𝑠) =
𝑠(𝑠2 + 6𝑠 + 9)
5(𝑠 + 2)
c. 𝐺8 (𝑠) = 2
𝑠(𝑠 + 6𝑠 + 34)
Solution 4a:
5(𝑠 + 2) 5(𝑠 + 2) 𝐴 𝐵 𝐶
𝐺6 (𝑠) = = = + +
𝑠(𝑠2 + 8𝑠 + 15) 𝑠(𝑠 + 3)(𝑠 + 5) 𝑠 𝑠 + 3 𝑠 + 5
Solve for the coefficients.
5(𝑠 + 2) 2
𝐴= =
(𝑠 + 3)(𝑠 + 5) 𝑠→0 3
5(𝑠 + 2) 5
𝐵= =
𝑠(𝑠 + 5) 𝑠→−3 6
5(𝑠 + 2) 3
𝐶= =−
𝑠(𝑠 + 3) 𝑠→−5 2
Thus,
2 5 3
𝐺6 (𝑠) = + −
3𝑠 6(𝑠 + 3) 2(𝑠 + 5)
Solution 4b:
5(𝑠 + 2) 5(𝑠 + 2) 𝐴 𝐵 𝐶
𝐺7 (𝑠) = 2
= 2
= + +
𝑠(𝑠 + 6𝑠 + 9) 𝑠(𝑠 + 3) 𝑠 𝑠 + 3 (𝑠 + 3)2
Expand to segregate like terms.
5(𝑠 + 2) = 𝐴(𝑠 + 3)2 + 𝐵𝑠(𝑠 + 3) + 𝐶𝑠
5𝑠 + 10 = 𝐴(𝑠2 + 6𝑠 + 9) + 𝐵𝑠2 + 3𝐵𝑠 + 𝐶𝑠
5𝑠 + 10 = 𝐴𝑠2 + 6𝐴𝑠 + 9𝐴 + 𝐵𝑠2 + 3𝐵𝑠 + 𝐶𝑠
5𝑠 + 10 = (𝐴 + 𝐵)𝑠2 + (6𝐴 + 3𝐵 + 𝐶)𝑠 + 9𝐴
Equate.
(1) 𝐴 + 𝐵 = 0
(2) 6𝐴 + 3𝐵 + 𝐶 = 5
(3) 9𝐴 = 10
Solve for the coefficients.
9𝐴 = 10 𝐴+𝐵 =0 6𝐴 + 3𝐵 + 𝐶 = 5
10 𝐵 = −𝐴 𝐶 = 5 − 6𝐴 − 3𝐵
𝐴= 10
9 10 10
𝐵=− 𝐶 =5−6 −3 −
9 9 9
5
𝐶=
3
Thus,
10 10 5
𝐺7 (𝑠) = − +
9𝑠 9(𝑠 + 3) 3(𝑠 + 3)2
Solution 4c:
5(𝑠 + 2) 𝐴 𝐵𝑠 + 𝐶
𝐺8 (𝑠) = = + 2
𝑠(𝑠2+ 6𝑠 + 34) 𝑠 𝑠 + 6𝑠 + 34
Expand.
5(𝑠 + 2) = 𝐴(𝑠2 + 6𝑠 + 34) + (𝐵𝑠 + 𝐶)𝑠
5𝑠 + 10 = 𝐴𝑠2 + 6𝐴𝑠 + 34𝐴 + 𝐵𝑠2 + 𝐶𝑠
5𝑠 + 10 = (𝐴 + 𝐵)𝑠2 + (6𝐴 + 𝐶)𝑠 + 34𝐴
Equate.
(1) 𝐴 + 𝐵 = 0
(2) 6𝐴 + 𝐶 = 5
(3) 34𝐴 = 10
Solve for the coefficients.
34𝐴 = 10 𝐴+𝐵 =0 6𝐴 + 𝐶 = 5
10 𝐵 = −𝐴 𝐶 = 5 − 6𝐴
𝐴=
34 5 5
5 𝐵=− 𝐶 =5−6
𝐴= 17 17
17 55
𝐶=
17
Thus,
5 − 5 𝑠 + 55
𝐺8 (𝑠) = + 2 17 17
17𝑠 𝑠 + 6𝑠 + 34
5
5 17
𝑠 − 55
17
𝐺8 (𝑠) = − 2
17𝑠 𝑠 + 6𝑠 + 34
1.4 LAB
1. Use MATLAB to find 𝑃3 , 𝑃4 , and 𝑃5 in Prelab 1.
Program and Response:
(Option 1 – Showing Coefficients)
(Option 2 – Showing Polynomials)
4. Use only two MATLAB commands to find 𝐺2 (𝑠) expressed as factors in the numerator divided by factors
in the denominator.
Program and Response:
5. Using various combinations of 𝐺1 (𝑠) and 𝐺2 (𝑠), find 𝐺3 (𝑠), 𝐺4 (𝑠), and 𝐺5 (𝑠). Various combinations
implies mixing and matching 𝐺1 (𝑠) and 𝐺2 (𝑠) expressed as factors and polynomials. For example, in
finding 𝐺3 (𝑠), 𝐺1 (𝑠) can be expressed in factored form and 𝐺2 (𝑠) can be expressed in polynomial form.
Another combination is 𝐺1 (𝑠) and 𝐺2 (𝑠) both expressed as polynomials. Still another combination is
𝐺1 (𝑠) and 𝐺2 (𝑠) both expressed in factored form.
Program and Response:
Result of 𝐺3 (𝑠) with 𝐺1 (𝑠) expressed in factored form and 𝐺2 (𝑠) expressed in polynomial form
Result of 𝐺3 (𝑠) with 𝐺1 (𝑠) and 𝐺2 (𝑠) both expressed in polynomial form
Result of 𝐺3 (𝑠) with 𝐺1 (𝑠) and 𝐺2 (𝑠) both expressed in factor form
Result of 𝐺4 (𝑠) with 𝐺1 (𝑠) expressed in factored form and 𝐺2 (𝑠) expressed in polynomial form
Result of 𝐺4 (𝑠) with 𝐺1 (𝑠) and 𝐺2 (𝑠) both expressed in polynomial form
Result of 𝐺4 (𝑠) with 𝐺1 (𝑠) and 𝐺2 (𝑠) both expressed in factor form
Result of 𝐺5 (𝑠) with 𝐺1 (𝑠) expressed in factored form and 𝐺2 (𝑠) expressed in polynomial form
Result of 𝐺5 (𝑠) with 𝐺1 (𝑠) and 𝐺2 (𝑠) both expressed in polynomial form
Result of 𝐺5 (𝑠) with 𝐺1 (𝑠) and 𝐺2 (𝑠) both expressed in factor form
6. Use MATLAB to evaluate the partial fraction expansions shown in Prelab 4.
Program and Response:
1.5 POSTLAB
1. Discuss your findings for Lab 5. What can you conclude?
After finding 𝐺3 (𝑠), 𝐺4 (𝑠) and 𝐺5 (𝑠) with 𝐺1 (𝑠) expressed in factored form and 𝐺2 (𝑠) expressed in
polynomial form, the outcome is in factored form. With 𝐺1 (𝑠) and 𝐺2 (𝑠) both expressed as polynomial
form, the outcome is in polynomial form. With 𝐺1 (𝑠) and 𝐺2 (𝑠) both expressed as factored form, the
outcome is in factored form.
I conclude that the outcomes may vary on what forms (factored form and polynomial form) are being
programmed in MATLAB which is eventually tolerable, but the outcome chooses rather to be in factored
form when different forms in the program are there. Just in case, I want to change the outcome, let’s say,
from the factored form to the polynomial form, simply use tf(); in contradiction, use zpk(). It is also
important that when simplifying transfer functions, use minreal().
2. Discuss the use of MATLAB to manipulate transfer functions and polynomials. Discuss any
shortcomings in using MATLAB to evaluate partial fraction expansions.
MATLAB is very useful tool to manipulate them. Aside from the programming that looks actual
expressions of transfer functions and polynomials, MATLAB uses commands as simplified version to it.
For example in Lab 2, instead of programming
syms s;
P6 = expand((s+7)*(s+8)*(s+3)*(s+5)*(s+9)*(s+10));
For this reason, you need to understand the programing language of MATLAB especially we need to
evaluate mathematical expressions that we cannot solve manually in no time.
To evaluate partial fraction expansions, use partfrac() which instantly shows the result similar from
hand calculations. Although there are other ways to evaluate them in MATLAB, I prefer to use
partfrac().