![]() |
||
![]() |
Department of
Mathematics and Computer Science |
![]() |
![]() |
CS/Math 166 -- Winter, 2018
|
|
20 points DUE: noon: Wednesday, Feb 14, 2018 |
BACKGROUND:
In the class notes (p [4-14], in lecture 7),
the Companion Matrix of a polynomial
(with leading coefficient equal to 1) was defined.
This is a matrix in which all elements are zero except for
the "superdiagonal" (the diagonal right above the major diagonal
from a11 to ann) and the last row.
All elements in the superdiagonal are 1, and the last row
consists of the negatives of the coefficients starting with
the constant in the first column and ending with the coefficient
of xn-1 in column n.
(Alternatively, (1) one can make the subdiagonal all one's, and the last column the negatives of the coefficients with the constant in the first row [this is the matrix transpose of the other definition], or (2) one can make the subdiagonal all one's, and the first row the negatives of the coefficients [which is what Matlab (or Octave) does] with the constant in the last column [this is a 180o rotation], and achieve an equivalent "companion" matrix.)
I also stated a theorem which says that the eigenvalues of the companion matrix were the roots of the corresponding polynomial.
In Matlab/Octave, the internal function compan(u) will create a companion matrix of a polynomial whose coefficients are stored in the vector u with the constant last. I.e., the polynomial y = 3x2 - 5x + 7 would have a coefficient vector u = [3 -5 7]. (NOTE: coefficients of zero MUST be explicitly included.)
(For your information, the Matlab (Octave) compan(u) function merely uses the following three command lines to determine the degree of the polynomial [one less than the length of the coefficient vector], then to create a matrix with one's in the subdiagonal, and finally to replace the first row with the negatives of the scaled coefficients.)n=length(u)-1; A= diag(ones(n-1,1),-1); A(1,:) = -u(2:n+1)./u(1);
To determine the roots of a polynomial, one need only use the Matlab/Octave function eig(A) to find the eigenvalues of A. (Note that eig also will find the eigenvectors, not needed for this problem -- see help eig for details.)
Matlab/Octave also has an internal function roots(u) which will create the companion matrix and find the eigenvalues in one step.
HERE IS THE PROBLEM TO BE DONE:
Write a function to use the two-step process in Matlab/Octave
to find the roots of the two polynomials given below.
(I.e., first find the companion matrix, and
display it; and then find the eigenvalues and output them),
Ideally the computation of the roots and the outputting of the results would be written up as a Matlab/Octave function and a driver script would contain the two vectors of polynomial coefficients.
Polynomials to be solved:
In addition, find the professional software which finds eigenvalues, RG, which is part of the EISPACK package. This calculates the eigenvalues of a general matrix,
How do you get the EISPACK routine RG?
Good question!
Use any web browser and enter the following address: http://www.netlib.org. This is a repository of mathematical software and other information. Click on the first listed option, Browse the Netlib repository.
Then click on eispack, and then click on rg.f (not the one including dependencies).
Print out this page and turn it in with the rest of the assignment.
Turn in your source file (i.e., any program code file) and the output/diary file. Also turn in the code for the RG subroutine.
As usual, your completed program may be turned in to my office, O'Connor 7, or to my mailbox in O'Connor 31. Please staple the pages yourself and do not turn in disconnected pages!
This page is maintained by Dennis C. Smolarski, S.J.
Email: dsmolarski "at" scu.edu
Last changed: 3 November 2017.