>> From: "Nathan Sokalski"
As you may know, there is no command to visually display trapezoid() like
there is for leftsum, rightsum, and middlesum. I decided to write my own,
and I have been able to make it work for some functions, but not others.
What I have concluded is that functions containing commands (sin(), ln(),
etc.) do not work, but functions without commands (x^2, 2*x+4, etc.) will
work. However, I also noticed that the ^ operator works for integer
exponents but not fractional. My procedure is shown below. How do I make my
procedure work for all functions?
trapezoidplot := proc (func, a, b, partitions) local interval, i, x1, y1,
x2, y2, curve, yview; interval := (b-a)/partitions; yview :=
min(0,evalf(minimize(func(x),x,a .. b))) .. max(0,evalf(maximize(func(x),x,a
.. b))); x2 := a; y2 := func(a); side.0 := PLOT(CURVES([[x2, y2], [x2,
0]],COLOR(RGB,0,0,0)),VIEW(a .. b,yview)); for i to partitions do x1 := x2;
y1 := y2; x2 := evalf(a+i*interval); y2 := func(x2); seg.i :=
PLOT(CURVES([[x1, y1], [x2, y2]],COLOR(RGB,0,0,0)),VIEW(a ..
b,yview),THICKNESS(2)); side.i := PLOT(CURVES([[x2, y2], [x2,
0]],COLOR(RGB,0,0,0)),VIEW(a .. b,yview)) od; with(plots); curve :=
plot(func(x),x = a .. b,thickness = 2); display(curve,[seq(side.j,j = 0 ..
partitions)],[seq(seg.h,h = 1 .. partitions)]) end:
NOTE: func must be defined with the <name>:=x-><function> method beforehand,
and entered as <name>, not <name>(x). a and b are the left and right
endpoints of the graph. partitions is the number of partitions.
EXAMPLE:
STUDENT >f:=x->x^2;
STUDENT >trapezoidplot(f,0,3,10);
Nathan Sokalski
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at
http://profiles.msn.com.
|