Method of Undetermined Coefficients

A.2 Method of Undetermined Coefficients

A second − order difference equation has the form

yn ()a + 1 yn ( – 1 )a + 2 ( n – 2 ) = fn ()

(A.1) where and are constants and the right side is some function of . This difference equation a 1 a 2 n

expresses the output yn () at time as the linear combination of two previous outputs n yn ( – 1 ) and yn ( – 2 ) . The right side of relation (A.1) is referred to as the forcing function. The general (closed-form) solution of relation (A.1) is the same as that used for solving second − order differen- tial equations. The three steps are as follows:

1. Obtain the natural response (complementary solution) y C () n in terms of two arbitrary real

constants k 1 and , k 2 where a 1 and a 2 are also real constants, that is,

C () n = k 1 a 1 + k 2 a 2 (A.2)

2. Obtain the forced response (particular solution) y P () n in terms of an arbitrary real constant k 3 ,

* For an introduction and applications of the Z-transform please refer to Signals and Systems with MATLAB Computing and Simulink Modeling, Third Edition, ISBN 0-9744239-9-8.

† Newton’s method is discussed in Chapter 2. Numerical Analysis Using MATLAB ® and Excel ® , Third Edition

Copyright © Orchard Publications

Appendix A Difference Equations in Discrete-Time Systems

that is,

P () n = k 3 a 3 (A.3) where the right side of (A.3) is chosen with reference to Table A.1. *

TABLE A.1 Forms of the particular solution for different forms of the forcing function Form of forcing function

Form of particular solution a

Constant

k − a constant

2 an k − a is a constant k

0 + k 1 n + k 2 n + …k + k n − is constant k i

± ab n − a and b are constants Expression proportional to b

acos ( n ω ) or asin ( n ω )

k 1 cos ( n ω ) + k 2 sin ( n ω )

a. As in the case with the solutions of ordinary differential equations with con- stant coefficients, we must remember that if fn () is the sum of several terms, the most general form of the particular solution y P () n is the linear combina- tion of these terms. Also, if a term in y P () n is a duplicate of a term in the com-

plementary solution y C () n , we must multiply y P () n by the lowest power of n that will eliminate the duplication.

3. Add the natural response (complementary solution) y C () n and the forced response (particular solution) y P () n to obtain the total solution, that is,

4. Solve for k 1 and k 2 in (A.4) using the given initial conditions. It is important to remember that the constants k 1 and k 2 must be evaluated from the total solution of (A.4), not from the complementary solution y C () n .

It is best to illustrate the Method of Undetermined Coefficients via examples.

Example A.1

Find the total solution for the second − order difference equation – yn n ()5 – ---y n 1 ( – )1 + ---y n 2 ( – ) = 5 n ≥ 0 (A.5)

subject to the initial conditions y () – 2 = 25 and y () – 1 = 6 .

* Ordinary differential equations with constant coefficients are discussed in Chapter 5.

A − 2 Numerical Analysis Using MATLAB ® and Excel ® , Third Edition Copyright © Orchard Publications

Method of Undetermined Coefficients Solution:

1. We assume that the complementary solution y C () n has the form

C () n = k 1 a 1 + k 2 a 2 (A.6) The homogeneous equation of (A.5) is

yn ()5 – ---y n ( – 1 )1 + ---y n ( – 2 ) = 0 n ≥ 0 (A.7)

Substitution of n yn () = a into (A.7) yields

a – ---a

+ ---a

= 0 (A.8)

n – Division of (A.8) by 2 a yields

a – ---a + --- = 0 (A.9)

The roots of (A.9) are

a 1 = --- 1 a 2 = --- 1 (A.10)

and by substitution into (A.6) we obtain

– 2. Since the forcing function is n 5 , we assume that the particular solution is

P () n = k 3 5 (A.12) and by substitution into (A.5),

⎛⎞ 5 --- – ( n – 1 )

3 5 – k 3 ⎝⎠ 5 + k 3 ⎛⎞ --- ⎝⎠ 5 = 5

– Division of both sides by n 5 yields

or k 3 = 1 and thus

P () n = 5 (A.13) The total solution is the addition of (A.11) and (A.13), that is,

– yn n () = y

C ()y n + P () n = k 1 2 + k 2 3 + 5 (A.14)

Numerical Analysis Using MATLAB ® and Excel ® , Third Edition

Copyright © Orchard Publications

Appendix A Difference Equations in Discrete-Time Systems

To evaluate the constants k 1 and k 2 we use the given initial conditions, i.e., s y () – 2 = 25 and

y () – 1 = 6 . For n = – 2 , (A.14) reduces to

2 2 y 2 () – 2 = k

1 2 + k 2 3 + 5 = 25

from which 4k 1 + 9k 2 = 0 (A.15)

For n = – 1 , (A.14) reduces to

1 1 y 1 () – 1 = k

from which 2k 1 + 3k 2 = 1 (A.16)

Simultaneous solution of (A.15) and (A.16) yields

and by substitution into (A.14) we obtain the total solution as

⎝ – --- ⎠ 3 + 5 n ≥ 0 2 (A.18) 3 To plot this difference equation for the interval 0 ≤≤ n 10 , we use the following MATLAB

script: n=0:1:10; yn=1.5.*2.^( −n)−(2./3).*3.^(−n)+5.^(−n); stem(n,yn); grid The plot is shown in Figure A.1.

Figure A.1. Plot for the difference equation of Example A.1

A − 4 Numerical Analysis Using MATLAB ® and Excel ® , Third Edition Copyright © Orchard Publications

Method of Undetermined Coefficients Example A.2

Find the total solution for the second − order difference equation – yn n ()3 – ---y n 1 ( – )1 + ---y n 2 ( – ) = 1 + 3 n ≥ 0 (A.19)

subject to the initial conditions y () – 2 = 0 and y () – 1 = 2

Solution:

1. We assume that the complementary solution y C () n has the form

C () n = k 1 a 1 + k 2 a 2 (A.20) The homogeneous equation of (A.19) is

yn ()3 – ---y n 1 ( – )1 + ---y n 2 ( – ) = 0 n ≥ 0 (A.21)

Substitution of n yn () = a into (A.21) yields

a – ---a

+ ---a

= 0 (A.22)

n – Division of (A.22) by 2 a yields

a – ---a + --- 1 = 0 (A.23)

The roots of (A.23) are

1 a 1 = ---

a 2 = 1 (A.24)

and by substitution into (A.20) we obtain

C () n = k 1 ⎛⎞ --- ⎝⎠ + k 2 () 1 = k 1 2 + k 2 (A.25)

– 2. Since the forcing function is n 1 + 3 , in accordance with the first and third rows of Table A.1, we would assume that the particular solution is

P () n = k 3 + k 4 3 (A.26) However, we observe that both relations (A.25) and (A.26) contain common terms, that is, the

constants k 2 and k 3 . To avoid the duplication, we choose the particular solution as

P () n = k 3 n + k 4 3 (A.27) and by substitution of (A.27) into (A.19) we obtain

Numerical Analysis Using MATLAB ® and Excel ® , Third Edition

Copyright © Orchard Publications

Appendix A Difference Equations in Discrete-Time Systems

⎛⎞ --- 3 ⎛⎞ --- 3 – ( n – 1 ) 1 1 – ( n – 2 )

+ ⎝⎠ ---k 4 3 n – ⎝⎠ 2 3 ( ) + ⎛⎞ --- k 4 3 = 1 + 3

3 n + k 4 3 – --- k 3 n + --- k 3 – --- k 4 3 + ---k 3 n – k +

Equating like terms, we obtain

⎛⎞ 3 --- ⎝⎠ k 3 – k 3 = 2 1

and after simplification,

By substitution into (A.27),

P () n = 2n + 3 (A.28) The total solution is the addition of (A.25) and (A.28), that is,

– yn n () = y

C ()y n + P () n = k 1 2 + k 2 + 2n + 3 (A.29) To evaluate the constants k 1 and k 2 we use the given initial conditions, i.e., s y () – 2 = 0 and

y () – 1 = 2 . For n = – 2 , (A.29) reduces to

y 2 () – 2 = k

from which 4k 1 + k 2 = – 5 (A.30)

For n = – 1 , (A.29) reduces to

1 y 1 () – 1 = k

from which 2k 1 + k 2 = 1 (A.31) Simultaneous solution of (A.30) and (A.31) yields k 1 = – 3 k 2 = 7 (A.32) and by substitution into (A.29) we obtain the total solution as

A − 6 Numerical Analysis Using MATLAB ® and Excel ® , Third Edition Copyright © Orchard Publications

Method of Undetermined Coefficients

– yn n () = y

C ()y n + P () n = ( )2 – 3 + 7 + 2n + 3 n ≥ 0 (A.33) To plot this difference equation for the interval 0 ≤≤ n 10 , we use the following MATLAB

script: n=0:1:10; yn=( −3).*2.^(−n)+7+2.*n+3.^(−n); stem(n,yn); grid

Figure A.2. Plot for the difference equation of Example A.2

Example A.3

Find the total solution for the first-order difference equation

n – yn 1 ( ) 0.9y n 1 – ( – ) = 0.5 + ( 0.9 )

n ≥ 0 (A.34)

subject to the initial condition y () – 1 = 5

Solution:

1. We assume that the complementary solution y C () n has the form

C () n = k 1 a (A.35) The homogeneous equation of (A.34) is yn ( ) 0.9y n 1 – ( – ) = 0 n ≥ 0 (A.36)

Substitution of n yn () = a into (A.35) yields

n – a 1 – 0.9a = 0 (A.37)

Numerical Analysis Using MATLAB ® and Excel ® , Third Edition

Copyright © Orchard Publications

Appendix A Difference Equations in Discrete-Time Systems

n – Division of (A.37) by 1 a yields

a – 0.9 = 0

a = 0.9 (A.38) and by substitution into (A.35) we obtain

(A.39) n – 2. Since the forcing function is 1 0.5 + ( 0.9 ) , in accordance with the first and third rows of

C () n = k 1 ( 0.9 )

Table A.1, we would assume that the particular solution is

(A.40) However, we observe that both relations (A.39) and (A.40) contain common terms, that is,

P () n = k 2 + k 3 ( 0.9 )

the constants n k

1 ( 0.9 ) and k 3 ( 0.9 ) . To avoid the duplication, we choose the particular solu- tion as

(A.41) and by substitution of (A.41) into (A.34) we obtain

P () n = k 2 + k 3 n 0.9 ( )

2 + k 3 n 0.9 ( ) – 0.9k 2 – 0.9k 3 ( n – 1 ) 0.9 ( )

n – 0.1k 1

2 + k 3 n 0.9 ( ) – 0.9k 3 n 0.9 ( )

+ 0.9k 3 ( 0.9 )

– 1 n – 0.1k 1

2 + k 3 n 0.9 ( ) – 0.9k 3 n 0.9 ( ) 0.9 + 0.9k 3 ( 0.9 ) 0.9 = 0.5 + ( 0.9 )

n – 1 – 1 0.1k n

2 + k 3 n 0.9 ( ) – k 3 n 0.9 ( ) + k 3 ( 0.9 ) = 0.5 + ( 0.9 )

Equating like terms, we obtain

0.1k 2 = 0.5

and after simplification,

10 k 2 = 5 k 3 = ------

By substitution into (A.41),

y P () n = 5 + ------n 0.9 ( )

10 n

(A.42)

The total solution is the addition of (A.39) and (A.42), that is,

10 n

yn () = y C ()y n + P () n = k 1 ( 0.9 ) + ------n 0.9 ( ) + 5 (A.43)

A − 8 Numerical Analysis Using MATLAB ® and Excel ® , Third Edition Copyright © Orchard Publications

Method of Undetermined Coefficients

To evaluate the constant k 1 we use the given initial condition, i.e., y () – 1 = 5 . For n = – 1 , (A.43) reduces to

------k 1 – --------- = 0 9 81

from which

10 1 = ------

(A.44)

and by substitution into (A.43) we obtain the total solution as

n – 1 n – yn 1 () = ( 0.9 ) + n 0.9 ( ) + 5

n – yn 1 () = ( n + 1 ) 0.9 ( ) + 5 n ≥ 0 (A.45) To plot this difference equation for the interval 0 ≤≤ n 10 , we use the following MATLAB

script: n=0:1:10; yn=(n+1).*(0.9).^(n-1)+5; stem(n,yn); grid

Figure A.3. Plot for the difference equation of Example A.3

Example A.4

Find the total solution for the second − order difference equation – yn n ( ) 1.8y n 1 – ( – ) 0.81y n 2 + ( – ) = 2 n ≥ 0 (A.46)

Numerical Analysis Using MATLAB ® and Excel ® , Third Edition

Copyright © Orchard Publications

Appendix A Difference Equations in Discrete-Time Systems

subject to the initial conditions y () – 2 = 25 and y () – 1 = 6

Solution:

No initial conditions are given and thus we will express the solution in terms of the unknown constants.

1. We assume that the complementary solution y C () n has the form

C () n = k 1 a 1 + k 2 a 2 (A.47) The homogeneous equation of (A.46) is

yn ( ) 1.8y n 1 – ( – ) 0.81y n 2 + ( – ) = 0 n ≥ 0 (A.48)

Substitution of n yn () = a into (A.48) yields

n – 1 n – a 2 – 1.8a + 0.81a = 0 (A.49)

n – Division of (A.49) by 2 a yields

a 2 – 1.8a + 0.81 = 0 (A.50) The roots of (A.50) are repeated roots, that is,

a 1 = a 2 = 0.9 (A.51) and as in the case of ordinary differential equations, we accept the complementary solution to

be of the form

(A.52) – 2. Since the forcing function is n 2 , we assume that the particular solution is

C () n = k 1 ( 0.9 ) + k 2 n 0.9 ( )

P () n = k 3 2 (A.53) and by substitution into (A.46),

3 2 – k 3 ( 1.8 )2

+ k 3 ( 0.81 )2

– Division of both sides by n 2 yields

3 [ 1 – ( 1.8 )2 + ( 0.81 )2 ] = 1 k 3 [ 1 – 3.6 + 3.24 ] = 1 1 25

k 3 = ---------- = ------ 0.64 16

A − 10 Numerical Analysis Using MATLAB ® and Excel ® , Third Edition Copyright © Orchard Publications

Method of Undetermined Coefficients

and thus

– 25 n

y P () n = ⎛ ------ ⎞ ⎝ ⎠ 2 (A.54)

The total solution is the addition of (A.52) and (A.54), that is,

yn () = y C ()y n + P () n = k 1 ( 0.9 ) + k 2 n 0.9 ( ) + ⎛ ------ ⎞ ⎝

25 n –

16 ⎠ 2 (A.55)

Example A.5

For the second − order difference equation

n ≥ 0 (A.56) what would be the appropriate choice for the particular solution?

yn n ( ) 1.8y n 1 – ( – ) 0.81y n 2 + ( – ) = ( 0.9 )

Solution:

This is the same difference equation as that of Example A.4 where the forcing function is n ( 0.9 ) – instead of n 2 where we found that the complementary solution is

(A.57) Row 3 in Table A.1 indicates that a good choice for the particular solution would be n k

C () n = k 1 ( 0.9 ) + k 2 n 0.9 ( )

3 ( 0.9 ) . But this is of the same form as the first term on the right side of (A.57). The next choice would be a

term of the form n k

3 n 0.9 ( ) but this is of the same form as the second term on the right side of (A.57). Therefore, the proper choice would be

P () n = k 3 n ( 0.9 )

(A.58)

Example A.6

Find the particular solution for the first-order difference equation

⎛ – n yn π ( ) 0.5y n 1 ( – ) = sin ------ ⎞

n ≥ 0 (A.59)

Solution:

From Row 4 in Table A.1 we see that for a sinusoidal forcing function, the particular solution has the form

y P () n = k 1 sin ⎛⎞ ------ + cos ⎛⎞ ------ ⎝⎠ k 2 (A.60)

Numerical Analysis Using MATLAB ® and Excel ® , Third Edition

A − 11

Copyright © Orchard Publications

Appendix A Difference Equations in Discrete-Time Systems

and by substitution of (A.60) into (A.59)

⎛⎞ ------ n π

⎛⎞ n ------ π

⎛ ------ k n 1 sin + k 2 cos – 0.5k 1 sin – 0.5k cos = sin π ⎞

-------------------- ( n – 1 )π

-------------------- ( n – 1 )π

2 2 2 2 ⎝ 2 ⎠ ⎛⎞ n

π --- = sin ⎛ ------ π ⎞ ⎝⎠

n cos ⎛⎞

k sin ------ π 1 + k 2 ------ π – 0.5k

n 1 sin ------

π – π --- – 0.5k

n π 2 cos ------ –

(A.61)

From trigonometry,

n ------ π

– --- π = – cos ⎛ ------ π ⎞

sin

n cos ------ π – π = sin ⎛ n ------ π --- ⎞

and by substitution into (A.61)

k 1 sin ⎛⎞ ------ + k 2 cos ⎛⎞ ⎝⎠ ------ ⎝⎠ + 0.5k 1 cos ⎛⎞ ------ – 0.5k 2 sin ⎛⎞ ------

Equating like terms, we obtain k 1 – 0.5k 2 = 1 (A.63)

0.5k 1 + k 2 = 0 (A.64) and simultaneous solution of (A.63) and (A.64) yields

k 1 = --- 4 k

– 2 2 = ---

Therefore, the particular solution of (A.59) is

n y P () n = --- sin ⎛⎞ ------ π – --- 2 cos ⎛⎞ ------ π

A − 12 Numerical Analysis Using MATLAB ® and Excel ® , Third Edition Copyright © Orchard Publications

Appendix B

Introduction to Simulink ®

T standing Simulink, and for this purpose, it is highly recommended that the novice to MAT-

his appendix is a brief introduction to Simulink. This author feels that we can best intro- duce Simulink with a few examples. Some familiarity with MATLAB is essential in under-

LAB reader reviews Chapter 1 which serves as an introduction to MATLAB.