# Maple Project # 12-6-02 # Aarin Teague # Donna Chen # Josh Wilkerson # Maplet Tutorial to test integrals through areas under curves restart; with(Maplets):with(Maplets[Tools]):with(Maplets[Elements]):with(plots): StartEngine: # This is the Maplet Window. When the student presses a button to select a type of curve, a question pops up. The student enters their answer and then is able to check the answer and see a plot of the function. AreaUnderCurve:=Maplet(onstartup=RunWindow(MAIN), Window[MAIN]('title'="Area Under Curves", [ [ "Press the Button for the Function You Wish to Integrate"], [ Button("Linear", Evaluate ('function'="ask1")), Button("Trigonometric", Evaluate ('function'="ask2")), Button("Between Two Curves", Evaluate ('function'="ask3")), " ", Button("Plot It", 'onclick'='Plot_It'), Button("Quit", Shutdown()) ], [ TextBox['question']('width'=60, 'height'=2, 'editable'='false')], [ "Answer: ", TextField['answer']('width'=25), Button("Check Answer",Evaluate('function'="check")) ], [ TextField['reply']('width'=40, 'editable'='false')] ] ), Window[PlotIt]('title'="Plot", [ [ Plotter['theplot']('width'=500, 'height'=500)], [ Button("Close Plot", CloseWindow(PlotIt))] ] ), Action['Plot_It'](RunWindow(PlotIt), Evaluate('function'="plotfunc") ) ): # This procedure creates and displays a randomly generated linear function,and interval over which to integrate.. ask1:=proc() local lim1, lim2, a1, b1, rand5, randp5, coin, f, f1, interval1, x; global correctanswer, correctplot; rand5:=rand(-5..5); lim1:=rand5(); lim2:=rand5(); while (lim1=lim2) do lim1:=rand5(); end do; if lim1>lim2 then lim1,lim2:=lim2,lim1; #This will swap them. end if; randp5:=rand(1..5); coin:=rand(0..1): a1:=(-1)^coin()*randp5(); b1:=rand5(); while (a1*lim1+b1<0 or a1*lim2+b1<0) do #Check endpoints are positive. a1:=(-1)^coin()*randp5(); b1:=rand5(); end do; f:=a1*x+b1; f1:=convert(y=f,string); interval1:=substring(convert([lim1,lim2],string),2..-2); correctanswer:= int(f,x=lim1..lim2); Set('question'=cat("Find the area under the line ",f1," on the interval (", interval1, ").")): Set('answer'=""): Set('reply'=""): correctplot:=plot(f, x=lim1..lim2, thickness=5, color=green); end proc: # This procedure produces and displays a randomly generated sin function. ask2:=proc() local lim1, lim2, a2, b2, rand3, f, f2, interval2, x; global correctanswer, correctplot; rand3:=rand(1..3); lim1:=0; lim2:=rand3()*Pi; a2:=rand3(); b2:=rand3(); f:=a2+a2*sin(b2*x); f2:=convert(y=f,string); interval2:=substring(convert([lim1,lim2],string),2..-2); correctanswer:=int(f,x=lim1..lim2); Set('question'=cat("Find the area under the curve ",f2," on the interval (",interval2,").")): Set('answer'=""): Set('reply'=""): correctplot:=plot(f,x=lim1..lim2,thickness=5,color=red); end proc: # This procedure produces randomly generated linear and quadratic functions, computes an interval,and then displays them. ask3:=proc() local lim1, lim2, a,b,c,d,e, rand5, randp5, coin, lineq, quadeq, sol, lineq3, quadeq3, interval3; global correctanswer, correctplot; randp5:=rand(1..5); coin:=rand(0..1): a:=(-1)^coin()*randp5(); c:=(-1)^coin()*randp5(); rand5:=rand(-5..5); b:=rand5(); d:=rand5(); e:=rand5(); lineq:=a*x+b; quadeq:=c*x^2+d*x+e; sol:=solve(lineq=quadeq,x); if not type(sol[1],realcons) then c:=-c; quadeq:=c*x^2+d*x+e; sol:=solve(lineq=quadeq,x); end if; lim1, lim2:=sol; if lim1=lim2 then Set('question'="Error generating the question. Please click the button again."); return(); end if; if evalf(lim1)>evalf(lim2) then lim1,lim2:=lim2,lim1; #This will swap them. end if; lineq3:=convert(y=lineq,string); quadeq3:=convert(y=quadeq,string); interval3:=substring(convert([lim1,lim2],string),2..-2); correctanswer:=signum(c)*int(lineq-quadeq, x=lim1..lim2); Set('question'=cat("Find the area between the the two curves ",lineq3," and ", quadeq3," on the interval (",interval3,").")); Set('answer'=""): Set('reply'=""): correctplot:=plot([lineq,quadeq],x=lim1..lim2,thickness=5,color=[blue,green]) end proc: # This is the check procedure,that allows the student to check their answer. check:=proc() global correctanswer; local userarea; userarea:=Get(thismaplet,'answer'::'realcons'): if (userarea-correctanswer=0) then Set('reply'="Correct! You are super smart!") else Set('reply'="Wrong-O. What were you thinking?") end if; end proc: # This is the procedure for the command button that will graph the function. plotfunc:=proc() global correctplot; Set('theplot'=correctplot) end proc: Display( AreaUnderCurve );