Polynomials - Chapter 18 Polynomials 18.1 Roots MATLAB...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 18 Polynomials 18.1 Roots MATLAB performs numerous operations involving polynomials. The most common situation dealing with polynomials is finding its roots. A polynomial is uniquely defined by its coefficients. MATLAB represents polynomials by a vector containing the coefficients of the powers in descending order. For example, the polynomial 1 1 1 0 ( ) ...... n n n n p x a x a x a x a - - = + + + + is saved in MATLAB as a vector p where 1 1 0 p [ , ,...... , , ] n n a a a a - = . If a coefficient is zero, it must appear in the vector. After the coefficient vector is defined, the roots of the polynomial are returned in a column vector from a call to ' roots(p) '. The roots of a polynomial are found in the example below. The polynomial is evaluated at the roots (where it should be zero) and then plotted to verify it passes through the real roots. Example 18.1.1 p=[1,-10,42,-98,65] % Define coefficient vector for polynomial % p(x) = x 4 - 10x 3 + 42x 2 - 98x + 65 proots=roots(p); % Find roots of p(x) x=proots % Set x equal to row vector of roots of p(x)=0 y=p(1)*x.^4 + p(2)*x.^3 + p(3)*x.^2 + p(4)*x + p(5) % Evaluate p(x) % at each of its 4 roots xi=linspace(0,10,250); % Create xi vector for evaluating yi=p(xi) yi=p(1)*xi.^4 + p(2)*xi.^3 + p(3)*xi.^2 + p(4)*xi + p(5); % yi=p(xi) plot(xi,yi) % Plot y=p(x) vs x hold on axis([0 6 -50 50]) % Set scale for plot plot([0 10],[0 0]) % Plot x-axis xlabel('x'), ylabel('y') title('y=p(x) Vs. x') p = 1 -10 42 -98 65 x = 2.0000 + 3.0000i 2.0000 - 3.0000i 5.0000 1.0000 y = 1.0e-012 * -0.1990 + 0.1137i -0.1990 - 0.1137i -0.3411 0 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
0 1 2 3 4 5 6 -50 -40 -30 -20 -10 0 10 20 30 40 50 x y y=p(x) Vs. x The reverse process, i.e. obtaining the polynomial coefficients from the roots is easily accomplished using the function ' poly '. Example 18.1.2 pcoeffs=poly(proots) % Find coeff's of polynomial with roots 'proots' pcoeffs = 1.0000 -10.0000 42.0000 -98.0000 65.0000 2
Background image of page 2
18.2 Multiplication Multiplying two polynomials in MATLAB is as simple as defining the coefficient vectors and then performing a convolution using the ' conv ' function. Example 18.2.1 p=[1:2 -5:-4] % First polynomial is p(x) = x 4 + 2x 3 - 5x - 4 q=[1 0 -2 0] % Second polynomial is q(x) = x 3 -2x u=conv(p,q) p = 1 2 -5 -4 q = 1 0 -2 0 u = 1 2 -7 -8 10 8 0 Executing Example 18.2.1 shows that 4 3 3 7 6 5 4 3 ( ) ( ) ( 2 5 4) ( 2 ) 2 7 8 10 8 p x q x x x x x x x x x x x x = + - - - = + - - + + The roots of the product polynomial and the individual polynomials must agree. This is easily verified. Example 18.2.2 rp=roots(p) % Find roots of p(x) rq=roots(q) % Find roots of q(x) ru=roots(u) % Find roots of u(x)=p(x) q(x) rp = -3.1774 1.8558 -0.6784 rq = 0 1.4142 -1.4142 ru = 0 -3.1774 -1.4142 1.8558 1.4142 -0.6784 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
18.3 Addition Addition of polynomials is a bit more complicated than multiplication when the polynomials involved are not the same order. That is, MATLAB cannot add polynomials of different order directly because the coefficient vectors representing them are not the same size. The solution is to pad the lower order polynomial coefficient vector with
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 18

Polynomials - Chapter 18 Polynomials 18.1 Roots MATLAB...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online