Programming Previous page   Next Page

Converter Methods for the Polynom Class

A converter method converts an object of one class to an object of another class. Two of the most important converter methods contained in MATLAB classes are double and char. Conversion to double produces the MATLAB traditional matrix, although this may not be appropriate for some classes. Conversion to char is useful for producing printed output.

The Polynom to Double Converter

The double converter method for the polynom class is a very simple M-file, @polynom/double.m, which merely retrieves the coefficient vector.

On the object p,

the statement

returns

The Polynom to Char Converter

The converter to char is a key method because it produces a character string involving the powers of an independent variable, x. Therefore, once you have specified x, the string returned is a syntactically correct MATLAB expression, which you can then evaluate.

Here is @polynom/char.m.

Evaluating the Output

If you create the polynom object p

and then call the char method on p

MATLAB produces the result

The value returned by char is a string that you can pass to eval once you have defined a scalar value for x. For example,

See The Polynom subsref Method for a better method to evaluate the polynomial.


Previous page  The Polynom Constructor Method The Polynom display Method Next page

© 1994-2005 The MathWorks, Inc.