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

Roots of Polynomials

               displays



               z =
                  3.0000 - 4.0000i
                                                                       4
               In the example above, a multiplication (*) sign between   and   was not necessary because the
                                                                              j
               complex number consists of numerical constants. However, if the imaginary part is a function or
               variable such as  cos  x () , we must use the multiplication sign, that is, we must type cos(x)*j or
               j*cos(x).


               1.2 Roots of Polynomials

                                                                                   [
               In MATLAB, a polynomial is expressed as a row vector of the form  a   a   n –  1   a   a   a ]  2  1  0  . The
                                                                                     n
                         a
               elements   of this vector are the coefficients of the polynomial in descending order. We must
                          i
               include terms whose coefficients are zero.
               We can find the roots of any polynomial with the roots(p) function where p is a row vector con-
               taining the polynomial coefficients in descending order.



               Example 1.1
               Find the roots of the polynomial

                                                           3
                                                    4
                                                                  2
                                          p x() =  x – 10x +  35x –  50x + 24                           (1.1)
                                           1
               Solution:
               The roots are found with the following two statements. We have denoted the polynomial as p1,
               and the roots as roots_ p1.


               p1=[1  −10  35  −50  24]  %  Specify the coefficients of p1(x)

               p1 =
                    1   -10    35   -50    24
               roots_ p1=roots(p1)  %  Find the roots of p1(x)


               roots_p1 =
                  4.0000
                  3.0000
                  2.0000
                  1.0000
               We observe that MATLAB displays the polynomial coefficients as a row vector, and the roots as a
               column vector.




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