Programming Previous page   Next Page

Overloading Functions for the Polynom Class

MATLAB already has several functions for working with polynomials represented by coefficient vectors. They should be overloaded to also work with the new polynom object. In many cases, the overloading methods can simply apply the original function to the coefficient field.

Overloading roots for the Polynom Class

The method @polynom/roots.m finds the roots of polynom objects.

The statement

results in

Overloading polyval for the Polynom Class

The function polyval evaluates a polynomial at a given set of points. @polynom/polyval.m uses nested multiplication, or Horner's method to reduce the number of multiplication operations used to compute the various powers of x.

Overloading plot for the Polynom Class

The overloaded plot function uses both root and polyval. The function selects the domain of the independent variable to be slightly larger than an interval containing all real roots. Then polyval is used to evaluate the polynomial at a few hundred points in the domain.

Overloading diff for the Polynom Class

The method @polynom/diff.m differentiates a polynomial by reducing the degree by 1 and multiplying each coefficient by its original degree.


Previous page  Overloading Arithmetic Operators for polynom Listing Class Methods Next page

© 1994-2005 The MathWorks, Inc.