# Bracketing Method of Solving Continuous Equations given a Black Box Function # Yasskin, Meade 2009 # # ################################## # # Header For All Maplets restart: with(Maplets[Elements]):with(Maplets[Tools]): StartEngine(); randomize(): lightorange:="#FFB300": lightcyan:="#DDFFFF": lightblue:="#CFCFFF": lightgreen:="#CCFFCC": darkgreen:="#00C000": ColorBkgd:=wheat: ColorDefaultMenu:=lightcyan: ColorHelpMenu:=lightorange: ColorFileMenu:=pink: ColorFooter:=lightcyan: ColorNewButton:=magenta: # or Make, Save, Enter Problem ColorReturnButton:=magenta: ColorCloseButton:=pink: # or Quit, Clear, Reset, Cancel ColorHintButton:=lightorange: # or Syntax ColorPrevButton:=turquoise: # or Update ColorEnterButton:=turquoise: ColorSimplifyButton:=lightorange: ColorCheckButton:=green: ColorShowButton:=lightorange: ColorPlotButton:=gold: ColorPlotButtonFrgd:=black: ColorPlotFrame:=gold: ColorTableBkgd:=lightgreen: ColorCalculatorBkgd:=gold: ColorBlackBox:=black: ColorBlackBoxFrgd:=yellow: ColorMessage:=white: ColorMessageFrgd:=black: ColorInput:=turquoise: ColorInputFrgd:=black: ColorCorrect:=green: ColorCorrectFrgd:=black: ColorIncorrect:=red: ColorIncorrectFrgd:=white: ColorWarning:=yellow: ColorWarningFrgd:=black: ColorShow:=lightorange: ColorShowFrgd:=black: ColorHint:=lightorange: ColorHintFrgd:=black: # or Info, Syntax ColorDisable:=wheat: ColorDisableFrgd:=black: FontFooter:=Font("helvetica",10): FontSymbol:=Font("symbol",12): FontBig:=Font("times",20): FontInstr:=Font("helvetica", bold, 12): LIBLogo:=cat(libname,"/M4C/M4C.png"): Logo:="M4C.png": #LIBLogo:=cat(libname,"/M4C/WebALT_logo.png"): #Logo:="WebALT_logo.png": # ################################## # # Template Translation Table For All Maplets TEXTLprogrammers:= "Programmers: D.B. Meade & P.B. Yasskin": TEXTLcopyright:= "© Copyright: Maplets for Calculus 2006-10": #"© Copyright: WebALT 2006-07": TEXTLversion:= "M4C v1.3 July 2010": TEXTBQuit:= "Quit": TEXTBClose:= "Close": TEXTBCheck:= "Check": TEXTBShow:= "Show": TEXTBShowAll:= "Show All Steps": TEXTBCheckAns:= "Check Answer": TEXTBShowAns:= "Show Answer": TEXTBInstructions:= "Instructions": TEXTBHint:= "Hint": TEXTBHints:= "Hints": TEXTBSyntax:= "Syntax": TEXTBHintSyntax:= "Hints and Syntax": TEXTBPrev:= "Preview": TEXTBUpdate:= "Update": TEXTBDerivation:= "Derivation": TEXTBNewProblem:= "New Problem": TEXTBNewFunction:= "New Function": TEXTBNewGraph:= "New Graph": TEXTBNewEquation:= "New Equation": TEXTBNewLimit:= "New Limit": TEXTBNewDerivative:= "New Derivative": TEXTBNewIntegral:= "New Integral": TEXTBNewSequence:= "New Sequence": TEXTBNewSeries:= "New Series": TEXTBNewDiffEq:= "New Differential Equation": TEXTBNewCurve:= "New Curve": TEXTBEnterProblem:= "Enter Problem": TEXTBEnterFunction:= "Enter Function": TEXTBEnterGraph:= "Enter Graph": TEXTBEnterEquation:= "Enter Equation": TEXTBEnterLimit:= "Enter Limit": TEXTBEnterDerivative:= "Enter Derivative": TEXTBEnterIntegral:= "Enter Integral": TEXTBEnterSequence:= "Enter Sequence": TEXTBEnterSeries:= "Enter Series": TEXTBEnterDiffEq:= "Enter Differential Equation": TEXTBMake:= "Modify or Make Your Own Problem": TEXTBSaveClose:= "Save Problem and Close": TEXTBAskQuestion:= "Ask Question": TEXTBNextQuestion:= "Next Question": TEXTBHowtoAnswer:= "How to Answer": TEXTBEnter:= "Enter": TEXTBOK:= "OK": TEXTBAccept:= "Accept": TEXTBReturn:= "Return": TEXTBClear:= "Clear": TEXTBClearSelections:= "Clear Selections": TEXTBClearAll:= "Clear All Steps": TEXTBReset:= "Reset": TEXTBRestart:= "Restart": TEXTBCancel:= "Cancel": TEXTBPlot:= "Plot": TEXTBPlotIt:= "Plot It": TEXTBAnimate:= "Animate": TEXTBPlay:= "Play": TEXTBPause:= "Pause": TEXTBForward:= "Forward": TEXTBReverse:= "Reverse": TEXTBStep:= "Step": TEXTBUpdatePlot:= "Update Plot": TEXTBZoomIn:= "Zoom In": TEXTBZoomOut:= "Zoom Out": TEXTBPlotSetup:= "Plot Setup": TEXTBRefresh:= "Refresh": TEXTBCalculate:= "Calculate": TEXTBSimplify:= "Simplify": TEXTBFactor:= "Factor": TEXTBExpand:= "Expand": TEXTBNormalize:= "Normalize": TEXTBCombine:= "Combine": TEXTBRationalize:= "Rationalize": TEXTBSort:= "Sort": TEXTBDecimal:= "Decimal": TEXTBExact:= "Exact": TEXTCorrect:= " correct ": TEXTIncorrect:= "incorrect": TEXTAlmost:= " almost ": TEXTWarning:= " warning ": TEXTShown:= " shown ": TEXTSlower:= "Slower": TEXTFaster:= "Faster": TEXTEnterFormula:= " Enter Formula:": TEXTEvaluate:= " Evaluate:": TEXTApproximate:= " Approximate:": TEXTand:= " and ": TEXTor:= " or ": TEXTThus:= " Thus ": TEXTSo:= " So ": TEXTType:= " Type ": TEXTfor:= " for ": TEXTat:= " at ": TEXTorcheck:= " or check: ": TEXTvertical:= "vertical": TEXThorizontal:= "horizontal": TEXTleft:= "left": TEXTright:= "right": TEXTless:= "less": TEXTgreater:= "greater": TEXTCBDNE:= "does not exist": TEXTCBNone:= "None": TEXTCB11scaling:= "1-1 scaling": TEXTdefault:= " default ": TEXTCBDoNotShow:= "Do not show this window again.": TEXTRBNumeric:= "Numeric": TEXTRBSymbolic:= "Symbolic": TEXTRBTrue:= "True": TEXTRBFalse:= "False": TEXTRBT:= "T": TEXTRBF:= "F": TEXTRBOn:= "On": TEXTRBOff:= "Off": TEXTRed:= "Red": TEXTGreen:= "Green": TEXTBlue:= "Blue": TEXTCyan:= "Cyan": TEXTMagenta:= "Magenta": TEXTYellow:= "Yellow": TEXTRedR:= "R": TEXTGreenG:= "G": TEXTBlueB:= "B": TEXTRBPlot1:= "Plot # 1": TEXTRBPlot2:= "Plot # 2": TEXTRBPlot3:= "Plot # 3": TEXTRBPlot4:= "Plot # 4": TEXTRBPlot5:= "Plot # 5": TEXTRBPlot6:= "Plot # 6": TEXTRBconverge:= "converge": TEXTRBdiverge:= "diverge": TEXTRBconverges:= "converges": TEXTRBdiverges:= "diverges": TEXTRBdiverges2:= "diverges ": TEXTRBconvergent:= "Convergent": TEXTRBdivergent:= "Divergent": TEXTtitlePROBLEM:= "Modify or Make Your Own Problem": TEXTtitlePREVIEW:= "Preview": TEXTtitleHINT:= "Hint": TEXTtitleSYNTAX:= "Syntax": TEXTtitlePlotSetup:= "Plot Setup": TEXTCapGoal:= "Goal:": TEXTCapProbStat:= "Problem Statement:": TEXTCapSyntaxTutorial:= "Syntax Tutorial:": TEXTCapEnter:= "Enter:": TEXTCapSpecify:= "Specify:": TEXTCapTrueFalse:= "True or False?": TEXTCapCalculator:= "Calculator": TEXTCapPlot:= "Plot": TEXTCapLegend:= "Legend": TEXTCapEvaluate:= "Evaluate:": TEXTCapDataTable:= "Data Table": TEXTCapVis:= "Visualization": TEXTCapAnim:= "Animation": TEXTCapPreviewer:= "Previewer": TEXTCapHorRng:= "Horizontal Range:": TEXTxmin:= "xmin =": TEXTxmax:= "xmax =": TEXTCapVertRng:= "Vertical Range:": TEXTymin:= "ymin =": TEXTymax:= "ymax =": TEXTPlotWait:= #Use ColorHint " Please be patient while the plot is generated.": TEXTAnimWait:= " Please be patient while the animation is generated.": TEXTRotatePlot:= " You may rotate the plot with your mouse.": TEXTreplyNoCheck:= " You must enter an expression to be checked.": TEXTreplyNoCheckBoth:= " You must answer both questions before checking.": TEXTreplyNoChecks:= " You must answer all %a questions before checking.": TEXTreplyNoPrev:= " You must enter an expression to be previewed.": TEXTreplyNoSimplify:= " You must enter an expression to be simplified.": TEXTreplyNoFactor:= " You must enter an expression to be factored.": TEXTreplyNoExpand:= " You must enter an expression to be expanded.": TEXTreplyNoNormalize:= " You must enter an expression to be normalized.": TEXTreplyNoModify:= " You must enter an expression to be modified.": TEXTreplyNoPlot:= " Please select a plot.": TEXTreplyNoSelection:= " Please select an answer.": TEXTreplyNoSaveProblem:= " You must fill in all the boxes before saving the problem.": TEXTreplyNoSaveSettings:= " You must fill in all the boxes before saving the settings.": TEXTreplyNoSlider:= " Set the slider to a number between %a and %a": TEXTreplySideEqWrong:= " The %a side of your equation is wrong.": TEXTreplyBothSideEqWrong:= " Both sides of your equation are wrong.": TEXTreplySideIneqWrong:= " The %a side of your inequality is wrong.": TEXTreplyBothSideIneqWrong:= " Both sides of your inequality are wrong.": TEXTreplyNoConst:= " You forgot to add a constant of integration.": TEXTreplyManyConst:= " Your answer should have only one constant of integration.": TEXTreplyMinusErr:= " You have a minus sign error.": DNEset:= {"", undefined, Undefined, UNDEFINED, divergent, Divergent, DIVERGENT, diverges, Diverges, DIVERGES, dne, DNE, doesnotexist, DoesNotExist}: TEXTM_File:= "File": TEXTM_Fns:= "Functions": TEXTCBMI_polygen:= "Polynomials (Generalized)": TEXTCBMI_exp:= "Exponentials": TEXTCBMI_log:= "Logarithms": TEXTCBMI_trig:= "Trigonometric": TEXTCBMI_invtrig:= "Inverse Trigonometric": TEXTCBMI_hyper:= "Hyperbolic": TEXTCBMI_invhyper:= "Inverse Hyperbolic": TEXTCBMI_simpsubst:= "Allow Simple Substitutions": TEXTM_Rules:= "Rules": TEXTCBMI_prod:= "Product Rule": TEXTCBMI_quot:= "Quotient Rule": TEXTCBMI_power:= "Power Rule": TEXTCBMI_chain:= "Chain Rule": TEXTM_Methods:= "Methods": TEXTCBMI_subst:= "Substitution": TEXTCBMI_parts:= "Integration by Parts": TEXTCBMI_trigpow:= "Trigonometric Powers": TEXTCBMI_trigsubst:= "Trigonometric Substitution": TEXTCBMI_trigident:= "Trigonometric Identity": TEXTCBMI_parfrac:= "Partial Fractions": TEXTCBMI_impfrac:= "Improper Fraction": TEXTRBproper:= "only proper integrals": TEXTRBimproper:= "allow improper integrals": TEXTM_RulesProb:= "Rules per Problem": TEXTreply_manyrules:= " Problems which involve too many rules tend to become rather messy.": TEXTM_MaxTerms:= "Max # Terms": TEXTreply_manyterms:= " Problems with large numbers of terms tend to become rather messy.": TEXTM_TermsPoly:= "Terms in Polynomial": TEXTM_PowerProp:= "Power Properties": TEXTCBMI_neg:= "Allow Negatives": TEXTCBMI_frac:= "Allow Fractions": TEXTreply_largepower:= " Problems with large degree polynomials tend to become rather messy.": TEXTM_Help:= "Help": TEXTmenu_start:= "Getting Started": TEXTmenu_custom:= "Customized Problems": TEXTmenu_manip:= "Manipulating Functions": TEXTmenu_about:= "About this maplet": great:=[ " Bullseye.", " Right on the mark.", " Great.", " That's absolutely right.", " Awesome. You're unstoppable.", " Correct.", " WOW, nailed that one.", " You got it!", " YES! Right on.", " Way to go.", " Don't stop now.", " I knew you could do it!", " Perfect. You're unstoppable.", " Radical Dude.", " Power house.", " Sweet! Keep on Rockin'.", " You rock!", " You got those mad skills.", " Awesome!", " Wowzers! That was great!", " Awesome man!", " Good job! You really know what you are doing.", " You're awesome kid.", " Tearing it up.", " Right on the money.", " High Five!!!!!", " Cool Beans.", " What a nerd!", " You're so money.", " You're a genius.", " You hit the nail on the head.", " Excellent!", " If I had a cookie, I'd give it to you.", " You're a winner.", " That's a winner.", " Whoop! Way to go.", " That's the way, ah ha ah ha, I like it.", " Oh yeah!", " You're the bomb!", " That was fantastic!", " Oh Snap!", NULL ]: nextgeneric:=[ " Keep it up.", " Keep going.", NULL ]: nextprob:=[ " On to the next problem.", " Try another problem.", " You're ready for another problem.", NULL ]: nextquest:=[ " On to the next question.", " Try another question.", " You're ready for another question.", NULL ]: nextpart:=[ " On to the next part.", " Try another part.", " You're ready for another part.", NULL ]: nextstep:=[ " On to the next step.", " Try another step.", " You're ready for another step.", NULL ]: nexteq:=[ " On to the next equation.", " Try another equation.", " Solve another equation.", " You're ready for another equation.", NULL ]: nextfn:=[ " On to the next function.", " Try another function.", " You're ready for another function.", NULL ]: nextlim:=[ " On to the next limit.", " Try another limit.", " Compute another limit.", " You're ready for another limit.", " Find another limit.", NULL ]: nextderiv:=[ " On to the next derivative.", " Try another derivative.", " Compute another derivative.", " You're ready for another derivative.", " Differentiate another function.", NULL ]: nextinteg:=[ " On to the next integral.", " Try another integral.", " Compute another integral.", " You're ready for another integral.", " Integrate another function.", NULL ]: nextdiffeq:=[ " On to the next differential equation.", " Try another differential equation.", " You're ready for another differential equation.", " Analyze another differential equation.", NULL ]: nextseq:=[ " On to the next sequence.", " Try another sequence.", " Find the limit of another sequence.", " You're ready for another sequence.", NULL ]: nextser:=[ " On to the next series.", " Try another series.", " Sum another series.", " You're ready for another series.", NULL ]: almost:=[ " Close.", " Oh so close.", " Close call. ", " Near miss.", " Not quite good enough for government work.", " Ooooh...close.", " Yikes! Really close. You'll get it next time.", " Close, but no cigar.", " Slightly off.", " Off by a hair.", " Almost there.", " Almost got it.", NULL ]: sorry:=[ " Sorry, that's not right.", " Nope, but don't give up.", " Not quite, it's a little off.", " Bummer, thought you would get it this time.", " If you need help, please ask a human.", " I don't know where you went wrong.", " Sorry, killer problem.", " No, but don't blow it off.", " D'oh!", " That's whack.", " Thought you would get it this time.", " Nice try, but your answer is wrong.", " Ask your neighbor for help.", " Brutal kid.", " That won't fly.", " So close and yet so far.", " So, that was just practice.", " A swing and a miss.", " Better luck next time.", " Oops.", " Tilt. Play again.", " I know you can do better.", " Sorry Charlie.", " Tisk, tisk. It's a tough one.", " It takes a lot of wrongs to make a right.", " Even Einstein didn't get everything right.", " Today's not your lucky day.", " Don't quit your day job.", " You're colder than a polar bear's toenail.", op(almost), NULL ]: trygeneric:=[ " Fix your answer and check it again.", " Give it another try.", " Try again.", " Please try again.", NULL ]: tryhint:=[ " Try the hints and answer again.", " Read the hints and try again.", " Study the hints and answer again.", NULL ]: tryhelp:=[ " Try the Help menu and answer again.", " Look at the Help menu and try again.", NULL ]: showgeneric:=[ " OK That's just practice. But try doing it yourself.", " That's fine for practice. Try doing it yourself.", " Think about it and enter an answer yourself.", " Next time, compute an answer yourself.", " So that was practice. Try doing it yourself.", NULL ]: showhint:=[ " Next time, try the hints.", " Read the hints and enter an answer yourself.", NULL ]: showhelp:=[ " Next time, read the Help menu.", " Read the Help and enter an answer yourself.", NULL ]: # ################################## # Procs for all maplets. GetVersion:=proc() local S, S1, S3, S4; options `Copyright 2009-10, Philip B. Yasskin and Douglas B. Meade, Maplets for Calculus`; uses StringTools; S:=interface(version); S:=map( Trim, Split( S, "," ) ); S1:=Split(S[1], " " ); S3:=Split(S[3], " " ); S4:=Split(S[-1], " " ); sprintf("%s (%s)", S[2],S3[-1]); end proc: Calculator:=proc(CalcExact) local calc; options `Copyright 2006-10, Philip B. Yasskin and Douglas Meade, Maplets for Calculus`; if Get(CalcIn)="" then return; end if; if CalcExact then calc:=simplify(Get(CalcIn::realcons, corrections=true, update=true)): else calc:=evalf(Get(CalcIn::realcons, corrections=true, update=true)): end if; Set(CalcOut=calc): end proc: # ################################## # # Customize For Each Maplet with(plots):with(plottools): with(RandomTools): with(ListTools): alias(e=exp(1)): nextlocal:=[ NULL ]: trylocal:=[ " Read the Instructions and try again.", " Study the Instructions and answer again.", NULL ]: showlocal:=[ " Next time, try the Instructions.", " Read the Instructions and enter an answer yourself.", NULL ]: nexts1:=[ #Keep what is appropriate. This is for all but the last check. op(nextgeneric), #op(nextprob), #op(nextquest), op(nextpart), op(nextstep), op(nextlocal), NULL ]: nexts2:=[ #Keep what is appropriate. This is for the last check. #op(nextgeneric), op(nextprob), op(nextquest), op(nexteq), #op(nextfn), #op(nextlim), #op(nextderiv), #op(nextinteg), #op(nextdiffeq), #op(nextseq), #op(nextser), #op(nextlocal), NULL ]: trys:=[ #Keep what is appropriate. op(trygeneric), #op(tryhint), #op(tryhelp), op(trylocal), NULL ]: shows:=[ #Keep what is appropriate. op(showgeneric), #op(showhint), #op(showhelp), op(showlocal), NULL ]: randgreat:=rand(1..nops(great)): randnext1:=rand(1..nops(nexts1)): randnext2:=rand(1..nops(nexts2)): randalmost:=rand(1..nops(almost)): randsorry:=rand(1..nops(sorry)): randtry:=rand(1..nops(trys)): randshow:=rand(1..nops(shows)): # ################################## # # Put Translation Table For Specfic Maplet Here TEXTLasstprogrammer:= "Assistant Programmers: ": TEXTtitleMAIN:= "Bracketing Method for a Continuous Black Box Function": TEXTcaptionGoal:= "Problem Statement: Use the Bracketing Method to solve the equation:": TEXTLInterval:= "for x in the interval": TEXTLError:= "to within E <": TEXTAssumeCont:= "Assume f(x) is a continuous function.": TEXTCapCurrVals:= "Current Endpoints and Function Values:": TEXTCurrVala:= "f(a) =": TEXTCurrValb:= "f(b) =": TEXTlabel_blackboxfn:= "CONTINUOUS BLACK BOX FUNCTION": TEXTCapEvalfc:= "Step 1: Enter your choice for c and press Enter.": TEXTCapError:= "Step 2: Enter the error:": TEXTCapDecideNext:= "Step 3: Decide if another iteration is needed:": TEXTCurrSol:= "Current Solution:": TEXTLStop:= "Stop": TEXTLNext:= " OR Continue with new interval:": TEXTtitleInstr:= "Bracketing Method Instructions": TEXTCapIVT:= "Intermediate Value Theorem": TEXTCapBSM:= "Bracketing Method": TEXTHint0:= "The Bracketing Method of solving f(x) = L is based on the:": TEXTHint1:= "If f(x) is continuous on [a,b] and f(a) = A and f(b) = B, then f(x) takes on every value between A and B somewhere on the interval (a,b).": TEXTHint2:= "To solve f(x) = L: 1) Find numbers a and b so that L is between f(a) and f(b). So there is a solution on the interval (a,b). 2) Pick c between a and b and compute f(c). (c can be the midpoint (a + b)/2 but not necessarily.) 3) Stop if the error E = max(c-a,b-c) is less than the desired accuracy. Otherwise: a) If L is between f(a) and f(c), repeat the procedure on the interval (a,c). b) If L is between f(c) and f(b), repeat the procedure on the interval (c,b).": TEXTHint3:= "Select c by looking at the plot and the table. When you evaluate f(c), a point will be entered in the plot and the table.": TEXTreplyNew:= " Since f(%a) = %.3f is %s than %.3f, and f(%a) = %.3f is %s than %.3f, there must be a solution x in the interval ( %a, %a ).": TEXTreplyEmptyc:= " Enter an input value, c, for the function.": TEXTreplyFndSol:= " You found the x-coordinate of the solution is x = %.3f +/- %.3f.\nIn other words, %.3f < x < %.3f.": TEXTreplyNotInCurrInt:= " For the Bracketing Method, each guess must be a point in the current interval. Your c is not in the interval ( %a, %a ).": TEXTreplyEmptyError:= " Enter a value for E, the error.": TEXTreplyCorrectc:= " Your point is in the interval.": TEXTreplyIncorrectError:= " This is not the correct estimate for the error.": TEXTreplyCorrectError:= " This is the correct error estimate.": TEXTreplyEmptyNext:= " Decide if it's time to stop, or on which part of the interval the solution exists.": TEXTreplyReadyToStop:= " Check the error again; if E < %.3f, then you should stop.": TEXTreplyNotReadyToStop:= " The error is not yet small enough; decide which part of the interval includes the solution.": TEXTreplyWrongInterval:= " This interval does not include the solution.": TEXTreplySolveExact:= " At the point x = %a, the function is f(%a) = %.3f. So the equation has been solved.": TEXTlabel_CheckShowMidPt:= "Note: Check that c is in the interval or Show\n a random c. In both cases, f(c) is computed.": # ################################## plot0:=plot(0,x=0..10): xas_[4]:=[-4,-2,0,2]: xas_[8]:=[-6,-4,-2,0,2]: xas_[16]:=[-8,-6,-4,-2,0,2]: Es_[4]:=[.4,.2,.1,.05]: Es_[8]:=[.5,.4,.2,.1]: Es_[16]:=[1,.5,.4,.2]: NewProblem:=proc() global DONE, xas_, xa, xb, xleft, xright, Es_, E_, incr, f_, fleft, fright, L_, plotL, pts, plotpts, x_sol, plotsol; local dx_, df_, g, c1, c3, a3, c5, a5, gmin, gmax, gave, fave, fa, fb, fmin, fmax, pad; options `Copyright 2006-10, Philip B. Yasskin and Douglas B. Meade, Maplets for Calculus`; DONE:=false; dx_:=Generate(choose([4,8,16])); xa:=Generate(choose(xas_[dx_])); xb:=xa+dx_; xleft,xright:=xa,xb: E_:=Generate(choose(Es_[dx_])); incr:=Generate(truefalse); df_:=10001; while df_>10000 do g:=0; while nops(g)<2 or not type(g,`+`) do c1:=Generate(choose([0,1,1,2,2,4])); c3:=Generate(choose([0,1,1,2,2,1/2])); a3:=Generate(choose([-2,0,2,2,4,4,6])); c5:=Generate(choose([0,1,1/2,1/4])); a5:=Generate(choose([-2,0,2,2,4,4,6])); g:=c1*x+c3*(x-a3)^3+c5*(x-a5)^5; end do; gmin:=eval(g,x=xa); gmax:=eval(g,x=xb); df_:=gmax-gmin; end do; gave:=(gmax+gmin)/2; fave:=Generate(integer(range=ceil(gmin+.1*df_)..floor(gmax-.1*df_))); f_:=fave+`if`(incr,1,-1)*(g-gave); fa:=eval(f_,x=xa); fb:=eval(f_,x=xb); fmin,fmax:=min(fa,fb),max(fa,fb); fleft,fright:=fa,fb: L_:=Generate(integer(range=ceil(fmin+.1*df_)..floor(fmax-.1*df_))); pad:=dx_/20; plotL:=plot(L_, x=xa-pad..xb+pad, color=red, thickness=2, numpoints=2); pts:=evalf[4]([[xa,fa],[xb,fb]]): plotpts:=plot(pts, x=xa..xb, style=point, symbol=diagonalcross, symbolsize=20, color=blue); x_sol:=fsolve(f_=L_,x=xa..xb): plotsol:=plot([[x_sol,L_]], x=xa..xb, style=point, symbol=soliddiamond, symbolsize=25, color=green, thickness=2); Set(TFeq=sprintf("f(x) = %a", L_)); Set(TFInterval=sprintf("[%a,%a]",xa,xb)); Set(TFPrecision=sprintf("%.3f",E_)); Set(TFfleft=sprintf("f(%a) = %.3f",xa,fa), TFfleft(background)=ColorMessage); Set(TFfright=sprintf("f(%a) = %.3f",xb,fb), TFfright(background)=ColorMessage); Set(TFc="", TFc(editable)=true, TFc(background)=ColorInput); Set(TFfc="", TFfc(background)=ColorMessage); Set(BCkc(enabled)=true, BCkc(background)=ColorCheckButton); Set(MRc="", MRc(background)=ColorMessage); Set(BShc(enabled)=true, BShc(background)=ColorShowButton); Set(TFError="", TFError(editable)=false); Set(BCkError(enabled)=false, BCkError(background)=ColorDisable); Set(MRError="", MRError(background)=ColorMessage); Set(BShError(enabled)=false, BShError(background)=ColorDisable); Set(TFCurr_c="", TFCurr_c(background)=ColorMessage); Set(TFCurr_E="", TFCurr_E(background)=ColorMessage); Set(Bstop=false, Bstop(enabled)=false); Set(BrepXOne=false, BrepXOne(enabled)=false); Set(BrepXTwo=false, BrepXTwo(enabled)=false); Set(BCkNext(enabled)=false, BCkNext(background)=ColorDisable); Set(MRNext="", MRNext(background)=ColorMessage); Set(BShNext(enabled)=false, BShNext(background)=ColorDisable); Set(reply=sprintf(TEXTreplyNew, xa, fa, `if`(incr, TEXTless, TEXTgreater), L_, xb, fb, `if`(incr, TEXTgreater, TEXTless), L_, xa, xb), reply(background)=ColorHint, reply(foreground)=ColorHintFrgd); Set(Pfx=display(plotL,plotpts)); RefreshTable(); Set(Brefresh(enabled)=true, Brefresh(background)=ColorPlotButton, Brefresh(foreground)=ColorPlotButtonFrgd); end proc: RefreshTable:=proc() global DONE, L_, incr, pts, x_sol; local sep, sol, small, large, all, xs, fxs; options `Copyright 2006-10, Philip B. Yasskin and Douglas B. Meade, Maplets for Calculus`; sep:=`if`(DONE,"======","--------"); sol:=`if`(DONE,x_sol,"???"); small,large:=selectremove(a->a[2]map(convert,a,string),all))[]; Set(LTxs(itemlist)=xs): Set(LTfxs(itemlist)=fxs): end proc: Check_c:=proc() global f_, xleft, xright, xa, xb, pts, plotL, plotpts; local user_c, user_fc; options `Copyright 2006-10, Philip B. Yasskin and Douglas B. Meade, Maplets for Calculus`; if Get(TFc)="" then Set(TFfc=""); Set(MRc=TEXTWarning, MRc(background)=ColorWarning, MRc(foreground)=ColorWarningFrgd); Set(reply=TEXTreplyEmptyc, reply(background)=ColorWarning, reply(foreground)=ColorWarningFrgd); return; end if; user_c:=Get(TFc::realcons, corrections=true, update=true): (* This is the one place where the algorithm changes; the new point can be any point in the interior of the current interval *) if user_c<=xleft or xright<=user_c then Set(MRc=TEXTIncorrect, MRc(background)=ColorIncorrect, MRc(foreground)=ColorIncorrectFrgd); Set(reply=sprintf(TEXTreplyNotInCurrInt, xleft, xright), reply(background)=ColorIncorrect, reply(foreground)=ColorIncorrectFrgd); return end if; Set(TFc(editable)=false); user_fc:=eval(f_, x=user_c); Set(TFfc=sprintf("%.3f",user_fc)): Set(BCkc(enabled)=false, BCkc(background)=ColorDisable); Set(MRc=TEXTCorrect, MRc(background)=ColorCorrect, MRc(foreground)=ColorCorrectFrgd); Set(BShc(enabled)=false, BShc(background)=ColorDisable); Set(reply=cat(TEXTreplyCorrectc,nexts1[randnext1()]), reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd); pts:=sort([{pts[],evalf[4]([user_c,user_fc])}[]],(a,b)->evalb(a[1]evalb(a[1]0.005 then Set(MRError=TEXTIncorrect, MRError(background)=ColorIncorrect, MRError(foreground)=ColorIncorrectFrgd); Set(reply=sprintf(TEXTreplyIncorrectError), reply(background)=ColorIncorrect, reply(foreground)=ColorIncorrectFrgd); return end if; Set(TFError(editable)=false); Set(BCkError(enabled)=false, BCkError(background)=ColorDisable); Set(MRError=TEXTCorrect, MRError(background)=ColorCorrect, MRError(foreground)=ColorCorrectFrgd); Set(BShError(enabled)=false, BShError(background)=ColorDisable); Set(reply=cat(TEXTreplyCorrectError,nexts1[randnext1()]), reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd); Set(TFCurr_c(background)=ColorMessage); Set(TFCurr_E=sprintf("%.3f",new_E), TFCurr_E(background)=ColorWarning); if abs(new_fc-L_)<0.001 then # correct to 3 decimal places Set(reply=cat(sprintf(TEXTreplySolveExact,new_c,new_c,new_fc), nexts2[randnext2()]), reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd); return end if; Set(Bstop(enabled)=true); Set(BrepXOne(enabled)=true); Set(BrepXTwo(enabled)=true); Set(BCkNext(enabled)=true, BCkNext(background)=ColorCheckButton); Set(BShNext(enabled)=true, BShNext(background)=ColorShowButton); end proc: ShowError:=proc() global xleft, xright; local new_c, new_fc, new_E; options `Copyright 2006-10, Philip B. Yasskin and Douglas B. Meade, Maplets for Calculus`; new_c:=Get(TFc::realcons, corrections=true, update=true); new_fc:=eval(f_, x=new_c); new_E:=max(new_c-xleft,xright-new_c); Set(TFError=sprintf("%.3f",new_E), TFError(editable)=false); Set(BCkError(enabled)=false, BCkError(background)=ColorDisable); Set(MRError=TEXTShown, MRError(background)=ColorShow, MRError(foreground)=ColorShowFrgd); Set(BShError(enabled)=false, BShError(background)=ColorDisable); Set(reply=shows[randshow()], reply(background)=ColorShow, reply(foreground)=ColorShowFrgd); Set(TFCurr_c(background)=ColorMessage); Set(TFCurr_E=sprintf("%.3f",new_E), TFCurr_E(background)=ColorWarning); if abs(new_fc-L_)<0.001 then # correct to 3 decimal places Set(reply=cat(sprintf(TEXTreplySolveExact,new_c,new_c,new_fc), nexts2[randnext2()]), reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd); return end if; Set(Bstop(enabled)=true); Set(BrepXOne(enabled)=true); Set(BrepXTwo(enabled)=true); Set(BCkNext(enabled)=true, BCkNext(background)=ColorCheckButton); Set(BShNext(enabled)=true, BShNext(background)=ColorShowButton); end proc: CheckNext:=proc() global DONE, incr, xleft, xright, fleft, fright, E_, plotL, plotpts, plotsol; local user_Stop, user_repXOne, user_repXTwo, new_c, new_fc, new_E; options `Copyright 2006-10, Philip B. Yasskin and Douglas B. Meade, Maplets for Calculus`; user_Stop:=Get(Bstop); user_repXOne:=Get(BrepXOne); user_repXTwo:=Get(BrepXTwo); if not (user_Stop or user_repXOne or user_repXTwo) then Set(MRNext=TEXTWarning, MRNext(background)=ColorWarning, MRNext(foreground)=ColorWarningFrgd); Set(reply=TEXTreplyEmptyNext, reply(background)=ColorWarning, reply(foreground)=ColorWarningFrgd); return; end if; new_c:=Get(TFc::realcons, corrections=true, update=true); new_fc:=Get(TFfc::realcons, corrections=true, update=true); new_E:=Get(TFError::realcons, corrections=true, update=true); if new_E-E_<0.001 then if user_Stop then DONE:=true; Set(MRNext=TEXTCorrect, MRNext(background)=ColorCorrect, MRNext(foreground)=ColorCorrectFrgd); Set(reply=cat(sprintf(TEXTreplyFndSol, new_c,new_E,new_c-new_E,new_c+new_E), nexts2[randnext2()]), reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd); else Set(MRNext=TEXTIncorrect, MRNext(background)=ColorIncorrect, MRNext(foreground)=ColorIncorrectFrgd); Set(reply=cat(sprintf(TEXTreplyReadyToStop,E_),trys[randtry()]), reply(background)=ColorIncorrect, reply(foreground)=ColorIncorrectFrgd); return end if; elif (incr and new_fc>L_) or (not incr and new_fcL_) or (not incr and new_fcL_) # or (not incr and new_fc>L_) or (new_fcL_) if user_repXTwo then xleft,fleft:=new_c,new_fc; Set(MRNext=TEXTCorrect, MRNext(background)=ColorCorrect, MRNext(foreground)=ColorCorrectFrgd); Set(reply=sprintf(TEXTreplyNew, xleft, fleft, `if`(incr, TEXTless, TEXTgreater), L_, xright, fright, `if`(incr, TEXTgreater, TEXTless), L_, xleft, xright), reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd); Set(TFfleft=sprintf("f(%a) = %.3f",new_c,new_fc), TFfleft(background)=ColorCorrect); Set(TFfright(background)=ColorMessage); else # So user_repXOne Set(MRNext=TEXTIncorrect, MRNext(background)=ColorIncorrect, MRNext(foreground)=ColorIncorrectFrgd); Set(reply=cat(TEXTreplyWrongInterval,trys[randtry()]), reply(background)=ColorIncorrect, reply(foreground)=ColorIncorrectFrgd); return end if; end if; Set(MRc="", MRc(background)=ColorMessage); if DONE then Set(TFc(background)=ColorWarning); Set(TFfc(background)=ColorWarning); Set(TFCurr_c(background)=ColorWarning); Set(Pfx=display(plotL,plotpts,plotsol)); RefreshTable(); else Set(TFc="", TFc(editable)=true); Set(TFfc=""); Set(BCkc(enabled)=true, BCkc(background)=ColorCheckButton); Set(BShc(enabled)=true, BShc(background)=ColorShowButton); Set(TFCurr_E(background)=ColorMessage); end if; Set(TFError="", TFError(editable)=false); Set(MRError="", MRError(background)=ColorMessage); Set(Bstop(enabled)=false); Set(BrepXOne(enabled)=false); Set(BrepXTwo(enabled)=false); Set(BCkNext(enabled)=false, BCkNext(background)=ColorDisable); Set(BShNext(enabled)=false, BShNext(background)=ColorDisable); end proc: ShowNext:=proc() global DONE, incr, xleft, xright, fleft, fright, E_, plotL, plotpts, plotsol; local new_c, new_fc, new_E; options `Copyright 2006-10, Philip B. Yasskin and Douglas B. Meade, Maplets for Calculus`; new_c:=Get(TFc::realcons, corrections=true, update=true); new_fc:=Get(TFfc::realcons, corrections=true, update=true); new_E:=Get(TFError::realcons, corrections=true, update=true); Set(MRNext=TEXTShown, MRNext(background)=ColorShow, MRNext(foreground)=ColorShowFrgd); if new_E-E_<0.001 then DONE:=true; Set(Bstop=true); Set(BrepXOne=false); Set(BrepXTwo=false); Set(reply=cat(sprintf(TEXTreplyFndSol, new_c,new_E,new_c-new_E,new_c+new_E), nexts2[randnext2()]), reply(background)=ColorHint, reply(foreground)=ColorHintFrgd); elif (incr and new_fc>L_) or (not incr and new_fcL_) Set(Bstop=false); Set(BrepXOne=false); Set(BrepXTwo=true); xleft,fleft:=new_c,new_fc; Set(reply=sprintf(TEXTreplyNew, xleft, fleft, `if`(incr, TEXTless, TEXTgreater), L_, xright, fright, `if`(incr, TEXTgreater, TEXTless), L_, xleft, xright), reply(background)=ColorHint, reply(foreground)=ColorHintFrgd); Set(TFfleft=sprintf("f(%a) = %.3f",new_c,new_fc), TFfleft(background)=ColorShow); Set(TFfright(background)=ColorMessage); end if; Set(MRc="", MRc(background)=ColorMessage); if DONE then Set(TFc(background)=ColorWarning); Set(TFfc(background)=ColorWarning); Set(TFCurr_c(background)=ColorWarning); Set(Pfx=display(plotL,plotpts,plotsol)); RefreshTable(); else Set(TFc="", TFc(editable)=true); Set(TFfc=""); Set(BCkc(enabled)=true, BCkc(background)=ColorCheckButton); Set(BShc(enabled)=true, BShc(background)=ColorShowButton); Set(TFCurr_E(background)=ColorMessage); end if; Set(TFError="", TFError(editable)=false); Set(MRError="", MRError(background)=ColorMessage); Set(Bstop(enabled)=false); Set(BrepXOne(enabled)=false); Set(BrepXTwo(enabled)=false); Set(BCkNext(enabled)=false, BCkNext(background)=ColorDisable); Set(BShNext(enabled)=false, BShNext(background)=ColorDisable); end proc: BracketNumeric:=Maplet(onstartup=RunWindow(MAIN), Window[MAIN]( title=TEXTtitleMAIN, defaultbutton=BCkc, BoxRow( halign=none, inset=0, spacing=0, background=ColorBkgd, [ halign=none, valign=none, inset=0, spacing=0, background=ColorBkgd, [ halign=none, background=ColorBkgd, Button(TEXTBNewProblem, Evaluate(function="NewProblem"), background=ColorNewButton), HorizontalGlue(), Button[BInstr](TEXTBInstructions, RunWindow(HINT), background=ColorHintButton), Button(TEXTBQuit, Shutdown(), background=ColorCloseButton) ], [ halign=none, valign=none, inset=0, spacing=0, background=ColorBkgd, [ halign=none, valign=none, inset=0, spacing=0, background=ColorBkgd, BoxColumn( halign=none, valign=none, inset=0, spacing=0, background=ColorBkgd, border=true, caption=TEXTcaptionGoal, [ halign=none, background=ColorBkgd, TextField[TFeq](width=10, editable=false, background=ColorMessage), TEXTLInterval, TextField[TFInterval](editable=false, width=4, background=ColorMessage), TEXTLError, TextField[TFPrecision](editable=false, width=3, background=ColorMessage), HorizontalGlue() ], [ halign=none, background=ColorBkgd, TEXTAssumeCont, HorizontalGlue() ] ), [ halign=none, background=ColorBkgd, border=true, caption=TEXTCapCurrVals, HorizontalGlue(), TEXTCurrVala, TextField[TFfleft](width=12, editable=false, background=ColorMessage), HorizontalGlue(), TEXTCurrValb, TextField[TFfright](width=12, editable=false, background=ColorMessage), HorizontalGlue() ], BoxRow( halign=none, inset=0, spacing=0, background=ColorBkgd, border=true, caption=TEXTCapEvalfc, [ halign=none, valign=none, spacing=0, background=ColorBlackBox, Label(TEXTlabel_blackboxfn, foreground=ColorBlackBoxFrgd), [ halign=none, inset=0, background=ColorBlackBox, HorizontalGlue(), Label("f(c) = f (", foreground=ColorBlackBoxFrgd, font=FontBig), TextField[TFc](width=6, editable=false, background=ColorInput), Label(") =", foreground=ColorBlackBoxFrgd, font=FontBig), TextField[TFfc]("", width=6, editable=false, background=ColorMessage), HorizontalGlue() ] ], [ halign=none, valign=none, inset=0, spacing=0, background=ColorBkgd, [ halign=none, background=ColorBkgd, HorizontalGlue(), Button[BCkc](TEXTBCheck, Evaluate(function="Check_c"), enabled=false, background=ColorDisable), TextField[MRc](width=6, editable=false, background=ColorMessage), Button[BShc](TEXTBShow, Evaluate(function="Show_c"), enabled=false, background=ColorDisable), HorizontalGlue() ], [ halign=none, background=ColorBkgd, TEXTlabel_CheckShowMidPt, HorizontalGlue() ] ] ), [ halign=none, background=ColorBkgd, border=true, caption=TEXTCapError, "E = max( c-a, b-c ) =", TextField[TFError](width=6, editable=false, background=ColorInput), HorizontalGlue(), Button[BCkError](TEXTBCheck, Evaluate(function="CheckError"), enabled=false, background=ColorDisable, foreground=ColorDisableFrgd), TextField[MRError](width=6, editable=false, background=ColorMessage), Button[BShError](TEXTBShow, Evaluate(function="ShowError"), enabled=false, background=ColorDisable, foreground=ColorDisableFrgd) ] ], [ halign=none, valign=none, background=ColorBkgd, border=true, caption=TEXTCapPlot, [ background=ColorPlotFrame, Plotter[Pfx](plot0, width=250, height=250) ] ] ], [ halign=none, inset=0, spacing=0, background=ColorBkgd, BoxRow( halign=none, background=ColorBkgd, border=true, caption=TEXTCurrSol, "x =", TextField[TFCurr_c](width=6, editable=false, background=ColorMessage), "+/-", TextField[TFCurr_E](width=6, editable=false, background=ColorMessage) ), BoxRow( halign=none, background=ColorBkgd, border=true, caption=TEXTCapDecideNext, RadioButton[Bstop](group=RBGroup, enabled=false, background=ColorInput, foreground=ColorInputFrgd), Label[Lstop](TEXTLStop, background=ColorInput, foreground=ColorInputFrgd), TEXTLNext, RadioButton[BrepXOne](group=RBGroup, enabled=false, background=ColorInput, foreground=ColorInputFrgd), Label[LrepXOne]("[a, c] ", background=ColorInput, foreground=ColorInputFrgd), RadioButton[BrepXTwo](group=RBGroup, enabled=false, background=ColorInput, foreground=ColorInputFrgd), Label[LrepXTwo]("[c, b] ", background=ColorInput, foreground=ColorInputFrgd), HorizontalGlue(), Button[BCkNext](TEXTBCheck, Evaluate(function="CheckNext"), enabled=false, background=ColorDisable, foreground=ColorDisableFrgd), TextField[MRNext](width=6, editable=false, background=ColorMessage), Button[BShNext](TEXTBShow, Evaluate(function="ShowNext"), enabled=false, background=ColorDisable, foreground=ColorDisableFrgd) ) ], BoxRow( halign=none, background=ColorBkgd, TextBox[reply](width=60, height=2, editable=false, background=ColorMessage), Label(Image(Logo)), Label(Image(LIBLogo)) ), BoxColumn( halign=none, background=ColorFooter, inset=0, spacing=0, [ background=ColorFooter, inset=0, spacing=0, Label(TEXTLprogrammers, font=FontFooter), HorizontalGlue(), Label(TEXTLcopyright, font=FontFooter), HorizontalGlue(), Label(TEXTLversion, font=FontFooter) ], [ background=ColorFooter, inset=0, spacing=0, HorizontalGlue(), Label(GetVersion(), font=FontFooter) ] ) ], [ valign=none, background=ColorTableBkgd, border=true, caption=TEXTCapDataTable, [ background=ColorTableBkgd, ListBox[LTxs](halign=center, [ "x", "________", "" ] ), ListBox[LTfxs](halign=center, [ "f(x)", "________", "" ] ) ], VerticalGlue(), Button[Brefresh](TEXTBRefresh, Evaluate(function="RefreshTable"), enabled=false, background=ColorDisable) ] )), Window[HINT]( title=TEXTtitleInstr, defaultbutton=CloseHINT, [ halign=none, background=ColorBkgd, [ halign=none, background=ColorBkgd, TEXTHint0, HorizontalGlue(), Button[CloseHINT](TEXTBClose, CloseWindow(HINT), background=ColorCloseButton) ], BoxColumn( halign=none, valign=none, inset=0, background=ColorBkgd, border=true, caption=TEXTCapIVT, TextBox(TEXTHint1, height=2, width=84, editable=false, background=ColorMessage) ), BoxColumn( halign=none, valign=none, inset=0, background=ColorBkgd, border=true, caption=TEXTCapBSM, TextBox(TEXTHint2, height=8, width=84, editable=false, background=ColorMessage) ), BoxColumn( halign=none, valign=none, inset=0, background=ColorBkgd, border=true, caption=TEXTBHints, TextBox(TEXTHint3, height=2, width=84, editable=false, background=ColorMessage) ) ] ), ButtonGroup[RBGroup]() ): Maplets[Display](BracketNumeric);