Library - classes

Library classes implements the constructors and methods of two classes: polynom for polynomials, and ratfun for rational functions. Basic arithmetic operators and functions are overloaded to support expressions with the same syntax as for numbers and matrices.

The following statement makes available functions defined in classes:

use classes

polynom::polynom

Polynom object constructor.

Syntax

use classes
a = polynom
a = polynom(coef)

Description

polynom(coef) creates a polynom object initialized with the coefficients in vector coef, given in descending powers of the variable. Without argument, polynom returns a polynom object initialized to 0.

The following operators and functions may be used with polynom arguments, with results analog to the corresponding functions of LME.

-minus +plus
^mpower rem
\mldivide roots
/mrdivide -uminus
*mtimes +uplus

Examples

use classes
p = polynom([3,0,1,-4,2])
  p =
    3x^4+x^2-4x+2
q = 3 * p^2 + 8
  q =
    27x^8+18x^6-72x^5+39x^4-24x^3+60x^2-48x+20

See also

polynom::disp, polynom::double, polynom::subst, polynom::diff, polynom::int, polynom::inline, polynom::feval, ratfun::ratfun

polynom::disp

Display a polynom object.

Syntax

use classes
disp(a)

Description

disp(a) displays polynomial a. It is also executed implicitly when LME displays the polynom result of an expression which does not end with a semicolon.

Example

use classes
p = polynom([3,0,1,-4,2])
  p =
    3x^4+x^2-4x+2

See also

polynom::polynom, disp

polynom::double

Convert a polynom object to a vector of coefficients.

Syntax

use classes
coef = double(a)

Description

double(a) converts polynomial a to a row vector of descending-power coefficients.

Example

use classes
p = polynom([3,0,1,-4,2]);
double(p)
  3 0 1 -4 2

See also

polynom::polynom

polynom::subst

Substitute the variable of a polynom object with another polynomial.

Syntax

use classes
subst(a, b)

Description

subst(a,b) substitutes the variable of polynom a with polynom b.

Example

use classes
p = polynom([1,2,3])
  p =
    x^2+3x+9
q = polynom([2,0])
  q =
    2x
r = subst(p, q)
  r =
    4x^2+6x+9

See also

polynom::polynom, polynom::feval

polynom::diff

Polynom derivative.

Syntax

use classes
diff(a)

Description

diff(a) differentiates polynomial a.

Example

use classes
p = polynom([3,0,1,-4,2]);
q = diff(p)
  q =
    12x^3+2x-4

See also

polynom::polynom, polynom::int, polyder

polynom::int

Polynom integral.

Syntax

use classes
int(a)

Description

int(a) integrates polynomial a.

Example

use classes
p = polynom([3,0,1,-4,2]);
q = int(p)
  q =
    0.6x^5+0.3333x^3-2x^2+2x

See also

polynom::polynom, polynom::diff, polyint

polynom::inline

Conversion from polynom object to inline function.

Syntax

use classes
fun = inline(a)

Description

inline(a) converts polynomial a to an inline function which can then be used with functions such as feval and ode45.

Example

use classes
p = polynom([3,0,1,-4,2]);
fun = inline(p)
  fun =
    <inline function>
dumpvar('fun', fun);
  fun = inline('function y=f(x);y=polyval([3,0,1,-4,2],x);');

See also

polynom::polynom, polynom::feval, ode45

polynom::feval

Evaluate a polynom object.

Syntax

use classes
y = feval(a, x)

Description

feval(a,x) evaluates polynomial a for the value of x. If x is a vector or a matrix, the evaluation is performed separately on each element and the result has the same size as x.

Example

use classes
p = polynom([3,0,1,-4,2]);
y = feval(p, 1:5)
  y =
    2    46   242   770  1882

See also

polynom::polynom, polynom::inline, feval

ratfun::ratfun

Ratfun object constructor.

Syntax

use classes
a = ratfun
a = ratfun(coefnum)
a = ratfun(coefnum, coefden)

Description

ratfun(coefnum,coefden) creates a ratfun object initialized with the coefficients in vectors coefnum and coefden, given in descending powers of the variable. Without argument, ratfun returns a ratfun object initialized to 0. If omitted, coefden defaults to 1.

The following operators and functions may be used with ratfun arguments, with results analog to the corresponding functions of LME.

inv *mtimes
-minus +plus
\mldivide -uminus
^mpower +uplus
/mrdivide   

Example

use classes
r = ratfun([3,0,1,-4,2], [2,5,0,1])
  r =
    (3x^4+x^2-4x+2)/(2x^3+5x^2+1)

See also

ratfun::disp, ratfun::inline, ratfun::feval, polynom::polynom

ratfun::disp

Display a ratfun object.

Syntax

use classes
disp(a)

Description

disp(a) displays rational function a. It is also executed implicitly when LME displays the ratfun result of an expression which does not end with a semicolon.

See also

ratfun::ratfun, disp

ratfun::num

Get the numerator of a ratfun as a vector of coefficients.

Syntax

use classes
coef = num(a)

Description

num(a) gets the numerator of a as a row vector of descending-power coefficients.

See also

ratfun::den, ratfun::ratfun

ratfun::den

Get the denominator of a ratfun as a vector of coefficients.

Syntax

use classes
coef = den(a)

Description

den(a) gets the denominator of a as a row vector of descending-power coefficients.

See also

ratfun::num, ratfun::ratfun

ratfun::diff

Ratfun derivative.

Syntax

use classes
diff(a)

Description

diff(a) differentiates ratfun a.

Example

use classes
r = ratfun([1,3,0,1],[2,5]);
q = diff(r)
  q =
    (4x^3+21x^2+30x-2)/(4x^2+20x+25)

See also

ratfun::ratfun

ratfun::inline

Conversion from ratfun to inline function.

Syntax

use classes
fun = inline(a)

Description

inline(a) converts ratfun a to an inline function which can then be used with functions such as feval and ode45.

See also

ratfun::ratfun, ratfun::feval, ode45

ratfun::feval

Evaluate a ratfun object.

Syntax

use classes
y = feval(a, x)

Description

feval(a,x) evaluates ratfun a for the value of x. If x is a vector or a matrix, the evaluation is performed separately on each element and the result has the same size as x.

Example

use classes
r = ratfun([1,3,0,1],[2,5]);
y = feval(r, 1:5)
  y =
    0.7143    2.3333    5.0000    8.6923   13.4000

See also

ratfun::ratfun, ratfun::inline, feval


Copyright 2001-2008, Calerga.
All rights reserved.