mathdemo.mws

The math package 3.6 for Maple 7

by Alexander F. Walz
alexander.f.walz@web.de

A demo session

This worksheet now presents almost all functions up to version 3.6.

> restart: libname := `e:/maple7/math`, libname: # input path to the math package here

First the math package has to be loaded with with . Make sure, that the path to the math package has been included in libname .

> with(math);

reading math ini file: e:/maple7/math/math.ini

`math v3.6.4 for Maple 6 & 7, current as of Septemb...

`written by Alexander F. Walz, alexander.f.walz@web...

`\n`
`\n`

Warning, the protected name extrema has been redefined and unprotected

[Arclen, END, PSconv, V, _Zval, arclen, assumed, as...
[Arclen, END, PSconv, V, _Zval, arclen, assumed, as...
[Arclen, END, PSconv, V, _Zval, arclen, assumed, as...
[Arclen, END, PSconv, V, _Zval, arclen, assumed, as...
[Arclen, END, PSconv, V, _Zval, arclen, assumed, as...
[Arclen, END, PSconv, V, _Zval, arclen, assumed, as...
[Arclen, END, PSconv, V, _Zval, arclen, assumed, as...
[Arclen, END, PSconv, V, _Zval, arclen, assumed, as...

To get a list of the various functions included in the package, read ?math .
To see how the package initializes its environment, see
?math/init .

If you want to know what has changed in the current version, check ?math/updates .

> fsolve(sin(x), x=-10 .. 10);

0.

The function fnull determines all zeros of a function in one real on a specified interval.

> fnull(sin(x), x=-10 .. 10);

-9.424777961, -6.283185307, -3.141592654, 0, 3.1415...

> fnull((x-4.11)^4, x=-10 .. 10, eps=1e-12);

4.11

> %-4.11;

0.

extrema determines extrema of a function in one real.

> extrema(x^5-x^3, x=-10 .. 10);

-1/5*sqrt(15), 1/5*sqrt(15)

> extrema(x^5-x^3, x=-10 .. 10, min);

1/5*sqrt(15)

> extrema(x^5-x^3, x=-10 .. 10, max);

-1/5*sqrt(15)


inflection returns inflection points of a function in one real.

> inflection(x^5-x^3, x=-10 .. 10);

-1/10*sqrt(30), 0, 1/10*sqrt(30)

> inflection(x^5-x^3, x=-10 .. 10, floats);

-.5477225575, 0, .5477225575

math/seqplot plots a sequence and - if it exists - the limiting function.

> seqplot((1+1/n)^n, n=1 .. 100, 2.5 .. 2.75, 'plotlimit', xtickmarks=5);

[Maple Plot]

math/cont determines whether a function is continuous at a point and also provides further information.

> cont((x^2-3*x+2)/(x^2+2*x-3), x=1);

false, undefined, removable = -1/4

There are some new types implemented in math, e.g. type/irrational and type/real .

> type(sqrt(2), irrational), type(sqrt(4), irrational), type(sqrt(2), real);

true, false, true

> f := x -> (1/2*x^3-3/2*x+1)/(x^2+3*x+2);

f := proc (x) options operator, arrow; (1/2*x^3-3/2...

math/asym returns the oblique asymptote of a function.

> asym(f(x));

1/2*x-3/2

math/un is a simplified unapply function, in many cases, the indeterminates do not have to be specified.

> a := un(%);

a := proc (x) options operator, arrow; 1/2*x-3/2 en...

math/gridplot plots graphs of one or more functions and also displays a grid.

> cartgridR3color := lightgray90: # override default grid color gray

> gridplot({f(x), a(x)}, x=-8 .. 8, y=-7 .. 7,

> discont=true,

> axes=box,

> units=[2, 2],

> step=[2, 2],

> color=darkcyan,

> axesfont=[HELVETICA, 10],

> titlefont=[HELVETICA, BOLD, 12],

> title=`Die Funktion f und ihre Asymptote a`);

[Maple Plot]

> gridplot([sin(t), cos(t), t=-Pi .. Pi], x=-2 .. 2, y=-2 .. 2,

> gridcolor=darkcyan,

> units=0.5,

> scaling=constrained);

[Maple Plot]

math/symmetry evaluates the symmetry of a function.

> symmetry(x^2);

true, even

> symmetry(x^3-x);

true, odd

> symmetry(exp(x));

false, `neither even nor odd`

math/deg and math/rad converts from radians to degress and vice versa.

> deg(Pi/4);

45

> rad(45);

1/4*Pi

math/mat simplifies defining matrices:

> A := mat(`1 a 3; 4 Pi 6; 8 9 sqrt(10)`);

A := matrix([[1, a, 3], [4, Pi, 6], [8, 9, sqrt(10)...

> linalg[det](A);

Pi*sqrt(10)+54-4*a*sqrt(10)+48*a-24*Pi

math/redefdim redefines the dimensions of an array.

> redefdim(A, 1 .. 2, 1 .. 2);

matrix([[1, a], [4, Pi]])

> linalg[det](A);

Pi-4*a

math/cartprod is an interface to combinat/cartprod .

> cartprod([[1, 2, 3, 4], [x, y, z]], 'p');

[1, x]

[1, y]

[1, z]

[2, x]

[2, y]

[2, z]

[3, x]

[3, y]

[3, z]

[4, x]

[4, y]

[4, z]

> p;

[1, x], [1, y], [1, z], [2, x], [2, y], [2, z], [3,...

> n := 'n': x := 'x':


With Version 2.0 of this package 15 new functions have been added to math:

Let s be the following power series:

> s := Sum((-1)^(n+1)*(x-1)^n/n, n=1 .. infinity);

s := Sum((-1)^(n+1)*(x-1)^n/n,n = 1 .. infinity)

Evaluate the radius of convergence of series s with PSconv :

> PSconv(s);

1

Give more details:

> PSconv(s, limit);

-Limit(-1/n*(n+1),n = infinity) = 1

Evaluate the range of convergence and evaluate its boundary points:

> PSconv(s, range);

RealRange(0,2)

Let f be a function in one real x:

> f := x -> x^3:

Determine the tangent and normal lines at the point x=1:

> tangente(f(x), x=1);

3*x-2

> normale(f(x), x=1);

-1/3*x+4/3

Plot the graph of f along with the tangent and normal lines with curveplot :

> curveplot(x^3, x=1, x=-3 .. 3, y=-3 .. 3,
tangentline=[color=blue],
normalline=[color=black],
vertical=[color=darkcyan, linestyle=2],
scaling=constrained, length=3);

[Maple Plot]

Determine the arc length of both explicit or parametric functions:

> assume(r, positive):

> 4*arclen(sqrt(r^2-x^2), x=0 .. r);

2*r*Pi

> arclen([t, t^2, 2/3*t^3], t=0 .. 3);

21

Determine linear and quadratic mean s:

> mean(sin(x), x=0 .. Pi, linear);

2*1/Pi

> mean(sin(x), x=0 .. Pi, quadratic);

1/2*sqrt(2)

math/curvature evaluates the curvature of a real-valued function:

> curvature(sin(x+t), x);

-sin(x+t)/((1+cos(x+t)^2)^3)^(1/2)

slopes of functions in x at a point a can also be determined:

> slopefn(x^2, x=t);

2*t

The angle of intersection between two curves can be computed easily:

> lineangle([2*x-3, 1/2*x+1]);

arctan(3/4)

Parametric functions can be converted into their explicit forms with convert/explicit :

> convert([1/2*t^2+2, 3/4*t^2+1], explicit);

3/2*x-2

The new function math/rotation evaluates characteristics of bodies of rotation:

> assume(r, positive):

> rotation(sqrt(r^2-x^2), x=0 .. r, area, xaxis);

2*Pi*r^2

> rotation(sqrt(x), x=0 .. 4, area, yaxis);

1/32*Pi*(132*sqrt(17)+ln(-4+sqrt(17)))

> rotation(x^2, x=0 .. sqrt(2), vol, yaxis);

2*Pi

> rotation(x*exp(-x), x=0 .. 1, vol, xaxis, float);

.2539377490

> rotation(sqrt(4-x), x=0 .. 4, xaxis, center);

4/3

> rotation((4-x)*sqrt(2*x), x=0 .. 4, xaxis, moment, float);

980.4162676*rho


Now some new utilities:

convert/range converts a RealRange expression or a relation or a set of two relations into a Maple range:

> convert(RealRange(0, Open(2)), range);

0 .. Open(2)

> lsg := solve((x-1)^2 < 1, {x});

lsg := {0 < x, x < 2}

> convert(lsg, range);

Open(0) .. Open(2)

convert/RealRange converts a range or a relation or a set of two relations into a RealRange expression.

> convert(lsg, RealRange);

RealRange(Open(0),Open(2))

The function math/V now also accepts strings and now is fully compatible with the linalg package:

> v := V(`1 2 3`);

v := VECTOR([1, 2, 3])

To display vectors vertically, use the vecvert switch :

> vecvert;

vertical

> eval(v);

MATRIX([[1], [2], [3]])

To change back to horizontal display, type

> vechori;

horizontal

> eval(v);

VECTOR([1, 2, 3])

getindets returns all indeterminates of an expression that are not of type/constant.

> getindets(Pi*x+y);

x, y

Functions introduced with math 3.0:

domainx determines the domain of a function in one real:

> f := x -> sqrt(x^3+4*x^2+4*x);

f := proc (x) options operator, arrow; sqrt(x^3+4*x...

> domainx(f(x));

-2, 0 .. infinity

isCont (an interface to cont) and isDiff determine whether a function is continuous and differentiable, respectively, at a given point.

> isCont(abs(x), x=0);

true

> isDiff(abs(x), x=0);

false

nondiff determines all those points at which a function is not differentiable:

> nondiff(arcsin(2*abs(x)*sqrt(1-x^2)), x);

{-1, 0, 1, 1/2*sqrt(2), -1/2*sqrt(2)}

END determines extrema at points where a function is not differentiable (extrema does not return results in this case):

> extrema(abs(sqrt(25-x^2)), x);

Error, (in signature/abs) too many levels of recursion

> END(abs(sqrt(25-x^2)), x);

-5, 5

ex calls both extrema and END and returns the combined result:

> ex(abs(sqrt(25-x^2)), x);

Error, (in signature) too many levels of recursion

singularity determines discontinuities and checks them for correctness (as opposed to discont):

> discont(sqrt(x), x);

{0}

> singularity(sqrt(x), x);

{}

> singularity(tan(x), x);

{Pi*_Z1+1/2*Pi}

Explicit values from the last result can be computed with _Zval :

> _Zval(%, -10 .. 10);

-5/2*Pi, -3/2*Pi, -1/2*Pi, 1/2*Pi, 3/2*Pi, 5/2*Pi

> evalf(%);

-7.853981635, -4.712388981, -1.570796327, 1.5707963...

> solve(x^3-1, x);

1, -1/2+1/2*I*sqrt(3), -1/2-1/2*I*sqrt(3)

getreals returns all real values from an expression or a sequence of expression that are real but not complex:

> getreals(%);

1

cutzeros removes trailing zeros from Maple floats:

> fsolve(x^2-1, x);

-1.000000000, 1.

> cutzeros(%);

-1, 1

inter determines the intersection between two intervals:

> r1 := solve(x>-10, x);

r1 := RealRange(Open(-10),infinity)

> r2 := solve(x<10, x);

r2 := RealRange(-infinity,Open(10))

> inter(r1, r2);

Open(-10) .. Open(10)

retrieve selects those expressions from a list that contain or do not certain subexpressions:

> t := trigsubs(tan(x^2-1));

t := [tan(-1+x^2), -tan(1-x^2), 2*tan(-1/2+1/2*x^2)...
t := [tan(-1+x^2), -tan(1-x^2), 2*tan(-1/2+1/2*x^2)...
t := [tan(-1+x^2), -tan(1-x^2), 2*tan(-1/2+1/2*x^2)...
t := [tan(-1+x^2), -tan(1-x^2), 2*tan(-1/2+1/2*x^2)...

> retrieve(t, [sin, cos, x^2-1]);

sin(-1+x^2)/cos(-1+x^2)

There are five new types included, among them type/cmplx which checks whether a value is complex but not real.

> type(1, complex);

true

> type(1, cmplx);

false

Version 3.0 includes improved functions: fnull, extrema, inflection, rangemembers, and cont .

fnull does now work with expression including logarithms, roots, abs, and tangents. Furthermore, the range does not need to be specified any more, see the online help for those functions for further details.

> fnull(abs(x), x);

0

> extrema(BesselJ(1, x), x, Use=fnull);

-8.536316366, -5.331442774, -1.841183781, 1.8411837...

> rangemembers({-1, 0, 0.5, exp(1), 5, Pi}, RealRange(Open(0), Pi));

exp(1), .5, Pi

> cont(sqrt(x), x=0);

true, right

Since the initialization procedure has been rewritten, it is now possible to define default values for

various math functions even before the package is initialized. The function setdef facilitates

assigning user-defined defaults to the global variables. See ? math,setdef and ? math/showdef for

further details.

math/makepoly generates a polynom from a list of coefficients or a set of solutions:

> p := 'p':

> poly := makepoly([1, 2, 3], x);

poly := x^2+2*x+3

> sols := {solve(poly)};

sols := {-1-I*sqrt(2), -1+I*sqrt(2)}

> makepoly(sols);

x^2+2*x+3

math/sortsols sorts solutions:

> gl1 := -2*x+2*y+7*z = 0:

> gl2 := x-y-3*z = 1:

> gl3 := 3*x+2*y+2*z = 5:

> solve({gl1, gl2, gl3}, {x, y, z});

{z = 2, x = 3, y = -4}

> sortsols(%);

x = 3, y = -4, z = 2

math/reduce reduces a system of linear equations:

> sys := {

> a-3*b+3/2*c-d=-104/10,

> -2*a+b+7/2*c+2*d=-165/10,

> a-2*b+12/10*c+2*d=0,

> 3*a+b-c-3*d=-7/10};

sys := {a-3*b+3/2*c-d = -52/5, -2*a+b+7/2*c+2*d = -...

> reduce(sys, p);

{a-3*b+3/2*c-d = -52/5, c+3*d = 147/50, -5*b+13/2*c...

math features some special numeric functions:

> p := x^4-12*x^3+25*x+116;

p := x^4-12*x^3+25*x+116

> fsolve(p, x, complex);

-1.225051807-1.467208009*I, -1.225051807+1.46720800...

> newp := makepoly({%}, x);

newp := x^4-11.99999999*x^3+116.0000000-.1004181779...
newp := x^4-11.99999999*x^3+116.0000000-.1004181779...

math/cancel deletes numerical values that are close to zero.

> poly := cancel(newp, eps=1e-5);

poly := x^4-11.99999999*x^3+116.0000000+25.00000000...

math/roundf rounds values:

> roundf(poly);

x^4-12*x^3+25*x+116

> roundf(evalf(Pi), 3);

3.142

math/cancel deletes trailing zeros from a float:

> cutzeros(poly);

x^4-11.99999999*x^3+116+25*x

math/slice slices floats:

> slice(%, 2);

x^4-11.99*x^3+116+25*x

math/seqby creates a sequence like seq but accepts step sizes:

> seqby(x, x=1 .. 3, 0.25);

1.00, 1.25, 1.50, 1.75, 2.00, 2.25, 2.50, 2.75, 3.0...

math/recseq iterates over a sequence recursively:

> recseq(1/n^n, n=2., 5);

2., .2500000000, 1.414213562, .6125473267, 1.350165...

> recseq(1/n^n, n=2, 5);

2, 1/4, 4^(1/4), 1/((4^(1/4))^(4^(1/4))), 1/((1/((4...

math features functions that determine whether a square matrix is of a specific type.

> B := dim(3, id);

B := matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

> isQuadratic(B);

true

> isIdentity(B);

true

> isSymmetric(B);

true

> isAntiSymmetric(B);

false

> isDiagonal(B);

true

> mainDiagonal(B);

[1, 1, 1]

math/interpol creates a polynom from a list of points.

> LL := [[0, 0], [3, 4], [5, 6], [1, 2]];

LL := [[0, 0], [3, 4], [5, 6], [1, 2]]

> interpol(LL);

1/15*x^3-3/5*x^2+38/15*x

> interpolplot(LL);

[Maple Plot]

math/tree returns the structure of a mathematical Maple expression.

> restart: libname := `e:/maple7/math`, libname: with(math):

reading math ini file: e:/maple7/math/math.ini

`math v3.6.4 for Maple 6 & 7, current as of Septemb...

`written by Alexander F. Walz, alexander.f.walz@web...

`\n`
`\n`

Warning, the protected name extrema has been redefined and unprotected

> tr := tree(a*(sin(x^3)+1));

tr := [`*`, a, [`+`, [sin, [`^`, x, 3]], 1]]

> printtree(tr);

*

a

+

sin

^

x

3

1

math now features a fully configurable Euro calculator which converts a currency to Euro, or a currency to another currency: convert/euro.

> convert(dem, euro); # Deutschmarks to Euro

.51

> convert(2*frf, euro, dem); # convert 2 French Franks to Deutschmarks

.60

To add another currency, assign its rate to the Euro to the _MathEuro table.

> _MathEuro[`cad`] := 1.5136; # Canadian Dollar

_MathEuro[cad] := 1.5136

> convert(1*cad, euro);

.66

You may add other currencies to the math.ini configuration file located in the math subdirectory.