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 object constructor.
a = polynom a = polynom(coef)
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.
|
|
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
polynom::disp, polynom::double, polynom::subst, polynom::diff, polynom::int, polynom::inline, polynom::feval, ratfun::ratfun
Display a polynom object.
disp(a)
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.
p = polynom([3,0,1,-4,2]) p = 3x^4+x^2-4x+2
Convert a polynom object to a vector of coefficients.
coef = double(a)
double(a) converts polynomial a to a row vector of descending-power coefficients.
p = polynom([3,0,1,-4,2]); double(p) 3 0 1 -4 2
Substitute the variable of a polynom object with another polynomial.
subst(a, b)
subst(a,b) substitutes the variable of polynom a with polynom b.
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
polynom::polynom, polynom::feval
Polynom derivative.
diff(a)
diff(a) differentiates polynomial a.
p = polynom([3,0,1,-4,2]); q = diff(p) q = 12x^3+2x-4
polynom::polynom, polynom::int, polyder
Polynom integral.
int(a)
int(a) integrates polynomial a.
p = polynom([3,0,1,-4,2]); q = int(p) q = 0.6x^5+0.3333x^3-2x^2+2x
polynom::polynom, polynom::diff, polyint
Conversion from polynom object to inline function.
fun = inline(a)
inline(a) converts polynomial a to an inline function which can then be used with functions such as feval and ode45.
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);');
polynom::polynom, polynom::feval, ode45
Evaluate a polynom object.
y = feval(a, x)
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.
p = polynom([3,0,1,-4,2]); y = feval(p, 1:5) y = 2 46 242 770 1882
polynom::polynom, polynom::inline, feval
Ratfun object constructor.
a = ratfun a = ratfun(coefnum) a = ratfun(coefnum, coefden)
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.
|
|
r = ratfun([3,0,1,-4,2], [2,5,0,1]) r = (3x^4+x^2-4x+2)/(2x^3+5x^2+1)
ratfun::disp, ratfun::inline, ratfun::feval, polynom::polynom
Display a ratfun object.
disp(a)
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.
Get the numerator of a ratfun as a vector of coefficients.
coef = num(a)
num(a) gets the numerator of a as a row vector of descending-power coefficients.
Get the denominator of a ratfun as a vector of coefficients.
coef = den(a)
den(a) gets the denominator of a as a row vector of descending-power coefficients.
Ratfun derivative.
diff(a)
diff(a) differentiates ratfun a.
r = ratfun([1,3,0,1],[2,5]); q = diff(r) q = (4x^3+21x^2+30x-2)/(4x^2+20x+25)
Conversion from ratfun to inline function.
fun = inline(a)
inline(a) converts ratfun a to an inline function which can then be used with functions such as feval and ode45.
ratfun::ratfun, ratfun::feval, ode45
Evaluate a ratfun object.
y = feval(a, x)
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.
r = ratfun([1,3,0,1],[2,5]); y = feval(r, 1:5) y = 0.7143 2.3333 5.0000 8.6923 13.4000