Note that your must use zeros to denote the missing

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: + 0x 3 + 0x 2 − 4x − 3, or, more simply, q(x) = 2x 4 − 4x − 3. Note that your must use zeros to denote the missing terms of the polynomial. previous page Some polynomials and their Matlab representations are displayed in Table 1. Note well the use of zeros as placeholders. contents next page back print doc Evaluating a Polynomial in Matlab Matlab has a number of useful routines for working with polynomials. 1 . One particularly useful 1 Use Matlab’s help facility to examine the help files for roots and poly. Although these routines will not be used in this close exit p (x) = x 3 − x 2 − 1 p=[1 -1 0 -1] q(x) = x 4 − x 2 − x q=[1 0 -1 -1 0] r (x) = x 4 − 2x 2 r=[1 0 -2 0 0] The Interpolating Polynomial Table 1 Matlab represents polynomials with vectors. routine is polyval. Enter the following command at the Matlab prompt to generate the resulting help file. >> help polyval POLYVAL Polynomial evaluation. Y = POLYVAL(P,X), when P is a vector of length N+1 whose elements are the coefficients of a polynomial, is the value of the polynomial evaluated at X. title page contents Y = P(1)*XˆN + P(2)*Xˆ(N-1) + ... + P(N)*X + P(N+1) previous page If X is a matrix or vector, the polynomial is evaluated at all points in X. See also POLYVALM for evaluation in a matrix sense. If p is a polynomial and x is a number, then polyval(p,x) evaluates the polynomial at the number x. For example, if p(x) = x 3 + 2x − 8, then p(−2) = −20. >> p=[1 0 2 -8]; >> x=-2; >> y=polyval(p,x) activity, you will have occasion to use them in later activities. next page back print doc close exit y= -20 The Matlab can evaluate a polynomial at each element of a vector or matrix. 2 For example, use your calculator to verify these calculations: p(x) = x 3 + 2x − 8, then p(−2) = −20, p(−1) = −11, p(0) = −8, p(1) = −5, and p(2) = 4. It is not difficult to evaluate the polynomial at each x -value; it’s just tedious. Matlab saves you some effort by evaluating the polynomial at each value of x with one command....
View Full Document

This document was uploaded on 02/14/2014.

Ask a homework question - tutors are online