%----------------------------------------------------------------------- % Use MATLAB's "roots" function to find all the polynomial roots % p(x) = a(1)*x^m + ... + a(m)*x + a(m+1) % Instructor: Nam Sun Wang %----------------------------------------------------------------------- % Start fresh ---------------------------------------------------------- clear all % Print a header ------------------------------------------------------- disp('Find the roots of a polynomial with real coefficients.') disp(' p(x) = a(1)*x^m + ... + a(m)*x + a(m+1) ') % Input coefficients --------------------------------------------------- coefficient = input ('Please enter coeffcients in a vector form: '); % Call a routine to solve the problem ---------------------------------- answer = roots(coefficient); % output your answer --------------------------------------------------- disp ('The roots are ...'); disp (answer);