Area approximation using rectangles.

First let us define our function as an expression.

> f := sqrt(x);

f := sqrt(x)

The wfucalc library contains commands that can be used to obtain numerical approximations

for definite integrals (or areas) using the left endpoint, midpoint, and right endpoint methods.

First load the library by using the with(wfucalc) command.

> with(wfucalc);

[eulerf, limitf, mygcd, myprint, nall, nallexp, nal...
[eulerf, limitf, mygcd, myprint, nall, nallexp, nal...
[eulerf, limitf, mygcd, myprint, nall, nallexp, nal...

The commands nleft, nmidpoint, nright will give the numerical approximations for

the left endpoint, midpoint, and right endpoint methods respectively.

> nleft(f,x=1..4,10);

4.514795679

> nmidpoint(f,x=1..4,10);

4.667600664

> nright(f,x=1..4,10);

4.814795679

The commands from the wfucalc library give numerical values quickly, and also

have the advantage that a list of values given in a table can also be used. The

values are assumed to be at equally spaced values of x, and the interval is

specified in the same way.

> v:=[9.3,9.0,8.3,6.5,2.3,-7.6,-10.5];

v := [9.3, 9.0, 8.3, 6.5, 2.3, -7.6, -10.5]

> nleft(v,x=0..6,6);

27.80000000

The number of intervals you specify must fit the number of values or an error

message will be generated.

> nright(v,x=0..6,4);

Error, (in wfucalc:-nright) n=4 must divide 6 (the no. of data points minus one.

> nmidpoint(v,x=0..6,3);

15.80000000

Functions with different definitions on different intervals can be defined

using the piecewise command. We define this as an actual Maple function

as opposed to the expressions that we have been using

> g := x -> piecewise(0<=x and x<2,4-2*x, 2<=x and x<6, -sqrt(4-(x-4)^2),6<=x and x<=7, x-6);

g := proc (x) options operator, arrow; piecewise(0 ...
g := proc (x) options operator, arrow; piecewise(0 ...

> g(x);

PIECEWISE([4-2*x, -x <= 0 and x < 2],[-sqrt(-12-x^2...

> plot(g(x),x=0..7,filled=true);

[Maple Plot]