Sysquake Pro – Table of Contents
Sysquake for LaTeX – Table of Contents
Library - polynom
Library polynom 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 polynom:
use polynom
Methods for conversion to MathML are defined in library polynom_mathml. Both libraries can be loaded with a single statement:
use polynom, polynom_mathml
Functions
polynom::polynom
Polynom object constructor.
Syntax
use polynom p = polynom p = 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. Function roots ignores leading zero coefficients.
Op. | Function | Op. | Function |
---|---|---|---|
- | minus | + | plus |
^ | mpower | rem | |
\ | mldivide | roots | |
/ | mrdivide | - | uminus |
* | mtimes | + | uplus |
Examples
use polynom 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 polynom disp(p)
Description
disp(p) displays polynomial p. It is also executed implicitly when LME displays the polynom result of an expression which does not end with a semicolon.
Example
use polynom p = polynom([3,0,1,-4,2]) p = 3x^4+x^2-4x+2
See also
polynom::double
Convert a polynom object to a vector of coefficients.
Syntax
use polynom coef = double(p)
Description
double(p) converts polynomial p to a row vector of descending-power coefficients.
Example
use polynom p = polynom([3,0,1,-4,2]); double(p) 3 0 1 -4 2
See also
polynom::subst
Substitute the variable of a polynom object with another polynomial.
Syntax
use polynom subst(a, b)
Description
subst(a,b) substitutes the variable of polynom a with polynom b.
Example
use polynom 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 polynom diff(p)
Description
diff(p) differentiates polynomial p.
Example
use polynom 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 polynom int(p)
Description
int(p) integrates polynomial p.
Example
use polynom 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 polynom fun = inline(p)
Description
inline(p) converts polynomial p to an inline function which can then be used with functions such as feval and ode45.
Example
use polynom 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 polynom y = feval(p, x)
Description
feval(p,x) evaluates polynomial p 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 polynom 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
polynom::mathml
Conversion to MathML.
Syntax
use polynom, polynom_mathml str = mathml(p) str = mathml(p, false)
Description
mathml(p) converts its argument p to MathML presentation, returned as a string.
By default, the MathML top-level element is <math>. If the result is to be used as a MathML subelement of a larger equation, a last input argument equal to the logical value false can be specified to suppress <math>.
Example
use polynom, polynom_mathml p = polynom([3,0,1,-4,2]); m = mathml(p); math(0, 0, m);
See also
ratfun::ratfun
Ratfun object constructor.
Syntax
use polynom r = ratfun r = ratfun(coefnum) r = 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.
Op. | Function | Op. | Function |
---|---|---|---|
inv | * | mtimes | |
- | minus | + | plus |
\ | mldivide | - | uminus |
^ | mpower | + | uplus |
/ | mrdivide |
Example
use polynom 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 polynom disp(r)
Description
disp(r) displays rational function r. It is also executed implicitly when LME displays the ratfun result of an expression which does not end with a semicolon.
See also
ratfun::num
Get the numerator of a ratfun as a vector of coefficients.
Syntax
use polynom coef = num(r)
Description
num(r) gets the numerator of r as a row vector of descending-power coefficients.
See also
ratfun::den
Get the denominator of a ratfun as a vector of coefficients.
Syntax
use polynom coef = den(a)
Description
den(a) gets the denominator of a as a row vector of descending-power coefficients.
See also
ratfun::diff
Ratfun derivative.
Syntax
use polynom diff(r)
Description
diff(r) differentiates ratfun r.
Example
use polynom 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::inline
Conversion from ratfun to inline function.
Syntax
use polynom fun = inline(r)
Description
inline(r) converts ratfun r 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 polynom y = feval(r, x)
Description
feval(r,x) evaluates ratfun r 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 polynom 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
ratfun::mathml
Conversion to MathML.
Syntax
use polynom, polynom_mathml str = mathml(r) str = mathml(r, false)
Description
mathml(r) converts its argument r to MathML presentation, returned as a string.
By default, the MathML top-level element is <math>. If the result is to be used as a MathML subelement of a larger equation, a last input argument equal to the logical value false can be specified to suppress <math>.
Example
use polynom, polynom_mathml r = ratfun([1,3,0,1],[2,5]); m = mathml(r); math(0, 0, m);