Area approximation using rectangles.
First let us define our function as an expression.
> 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);
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);
> nmidpoint(f,x=1..4,10);
> nright(f,x=1..4,10);
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];
> nleft(v,x=0..6,6);
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);
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(x);
> plot(g(x),x=0..7,filled=true);