Page 18 - Numerical Analysis Using MATLAB and Excel
P. 18

Evaluation of a Polynomial at Specified Values


               r3=[1  2  3  4]  %  Specify the roots of the polynomial

               r3 =
                    1     2     3     4

               poly_r3=poly(r3)  %  Find the polynomial coefficients

               poly_r3 =
                    1   -10    35   -50    24
               We observe that these are the coefficients of the polynomial p x()  of Example 1.1.
                                                                           1

               Example 1.4

                                                                        ,
                                                               ,
                                                                    ,
               It is known that the roots of a polynomial are  1 2 3 4 +       j5and 4 j5   . Find the coeffi-
                                                                                ,
                                                                                        –
                                                                      –
                                                                 –
                                                             –
               cients of this polynomial.
               Solution:
               We form a row vector, say r4 , with the given roots, and we find the polynomial coefficients with
               the poly(r) function as shown below.
               r4=[ −1   −2   −3   4+5j   4−5j ]

               r4 =
                 Columns 1 through 4
                 -1.0000   -2.0000   -3.0000   -4.0000 + 5.0000i
                 Column 5
                 -4.0000 - 5.0000i
               poly_r4=poly(r4)

               poly_r4 =
                    1    14   100   340   499   246
               Therefore, the polynomial is


                                                             3
                                                                     2
                                                     4
                                              5
                                   p x() =  x +  14x +   100x +  340x +  499x + 246                     (1.3)
                                     4

               1.4 Evaluation of a Polynomial at Specified Values

               The polyval(p,x) function evaluates a polynomial px()   at some specified value of the indepen-

                             x
               dent variable  .





               Numerical Analysis Using MATLAB® and Excel®, Third Edition                               1−5
               Copyright © Orchard Publications
   13   14   15   16   17   18   19   20   21   22   23