23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9 Classes and Objects<br />

Example — A Polynomial Class<br />

This example implements a <strong>MATLAB</strong> data type for polynomials by defining<br />

a new class called polynom. The class definition specifies a structure for<br />

data storage and defines a directory (@polynom) of methods that operate on<br />

polynom objects.<br />

This section covers<br />

• “Polynom Data Structure” on page 9-26<br />

• “Polynom Methods” on page 9-26<br />

• “The Polynom Constructor Method” on page 9-27<br />

• “Converter Methods for the Polynom Class” on page 9-28<br />

• “The Polynom display Method” on page 9-30<br />

• “The Polynom subsref Method” on page 9-31<br />

• “Overloading Arithmetic Operators for polynom” on page 9-32<br />

• “Overloading Functions for the Polynom Class” on page 9-34<br />

• “Listing Class Methods” on page 9-36<br />

Polynom Data Structure<br />

The polynom class represents a polynomial with a row vector containing<br />

the coefficients of powers of the variable, in decreasing order. Therefore,<br />

a polynom object p is a structure with a single field, p.c, containingthe<br />

coefficients. This field is accessible only within the methods in the @polynom<br />

directory.<br />

Polynom Methods<br />

To create a class that is well behaved within the <strong>MATLAB</strong> environment and<br />

provides useful functionality for a polynomial data type, the polynom class<br />

implements the following methods:<br />

• A constructor method polynom.m<br />

• A polynom to double converter<br />

9-26

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!