Functions defined by an algorithm
Forreference,seehere
- ExamplesinAnalysis
- TheEulermethodforan approximatesolutionofthedifferential equationy'=y
-
- Approximateanti-derivative
- Trajectories: Roadrunner andCoyote
- FunctionswithvaluesinIR
- FunctionswithvaluesinIR²
Examplesin Analysis
TheEuler methodforan approximatesolutionofthedifferential equationy'=y
Inthisexample,thebasicsteps tocreateanduseafunctiondefined byanalgorithmaredemonstrated.
Selecttheentryinthealgebra tabmenu.
Theprogram
Awindowopenswithanembryonicprogram.
Structure
Wemodifyline3andchoose Repeatinthelistontheleft.
Declarations
Wechangethedeclarationofthevariable y.
Withthecorrespondingmenuentry, aninputfieldopensforthe initialvalue.
Wereplace0by1theOK.
Wedeclareanewvariablep.
Weselecttheletterinthelistontheleftandweinitializelikefor y
LoopBody
WechoosetheentryAffect VariableintheLoop
Abarsimilartotheinitializationappears.Thevariablehastobe selectedinthealreadydeclaredvariables.
Thelineisinsertedaftertherepeat line
Wealsointroduceline6(below).
StopCondition
Wemodifyline7.
Wekeepthevariablexand wechangetheformula0into 2.
Thusthefunctionwillbedefinedover[0;2]
Execution
Beforedefiningthefunction,we havetocheckthattheprogramrunscorrectly.
Wechoosetostoptheprogrambefore 500iterations.
Ifourprogramiscorrectit muststopafter200iteration;this limitof500willnotbereached.
Wechoosealsoafunctionwithvaluesin IR(checkx’!y (x)).
Ifourprogramiscorrectxvaluesareincreasing.
WeactivatethemenuentryTest twice(oneforchoosingthevariabletodisplay,theothertorun).
Wecheckthattheprogramrunscorrectly. Thevaluesofx,yandpinthe iterationaredisplayedin columns.
Wefillthecommentfieldto reminduswhatthefunction,thenOK tocreatethefunction.
Usingthefunction
Thefunctionappearsinthe listof functionswiththecommentthatwehavechosen.
Abuttonwiththeletteralso appearsinthegraphic tab.Byactivatingthisbutton,the functionisgraphed.
Therealsoexistsanentryin thecurve menuofthegeometrytab.
Wecanchoosetodefinethe exponentialfunctionontheinterval[0, 2]andnotethat thecurvesaresuperimposed.
Amore accuratecomparisoncanbemadeusing thetable.
Wecanalsocreatethefunction f-g,toestimate thedifference.
Amessagewarnsthatthe function'suseislimitedtographics.
Indeed,wenotethatthe functionhhasadecentplot butCasyopéecannotcompute symbolicvalueash(2).
Anapproximatevalueofh(2) couldbeobtainedusing thetableorthepassingEvaluate Formula.
Approximate anti-derivative
Inthisexample,wewillshowhowCasyopée objectscanbeusedinan algorithm.
CasyopéeObjects
Createaparameterpfor thestepofthemethod,sothat wecanchangeit.
Createafunctionw,which canalsobechanged later.
Editingafunctiondefinedbyan algorithm
Byrightclicking onthelineinthelistoffunctions correspondingtothefunctionf,we willmodifyitsprogram.
Deletepdeclarationatline 2.Thuspisnowthe parameter.
Modifyalsolines4and 5andthecommentsandtest thealgorithm.
Leprogram terminates,nous
Theprogramterminates,wecanapply thechangetothefunction(OK).
Usingthefunction
Byanimatingtheparameterp, weseehowthefunction obtainedfitsthefunctiondefinedby
Belowforthevaluesofp1, 1/2and1/20.
Itisalsopossibletochangethe functionw.Herewejusttake w(x)=xetU(x)=1+x²/2.
Trajectories: RoadrunnerandCoyote
Functionswith valuesinIR
TheCoyoteispostedat20 mdistancefromtheexitofatunnel.
Roadrunnerexitsthetunnel onastraighttrailat aspeedof2m.s-1.
Coyote'srocketallows himtohaveaspeedof3m.s-1.
"Givenadirectionchosenbythe Coyote,canhecatchRoadrunner? ".
Functionsdefiningthetrajectories
Wedefineaparameterfor theslopeofthetrajectoryof Coyoteandanother forthetraveltime.
Roadrunner'strajectoryis thecurveofthefunctionb definedbythefollowingalgorithm.
Coyotte'strajectoryisthecurve ofthefunctioncdefinedby thefollowingalgorithm.
Usingthefunction
Oncethetwofunctionsandthe curvesarecreatedintheGeometry tabforagivenvalue ofa, weanimatethe parameterT
Withaslopeof9/10coyote passesBeepBeep!Missed again.
Functionswith valuesinIR²
ImaginenowthatCoyoteruns constantlytowardsBipBip, withaspeedof5m.s-1 and Roadrunner1m.s-1.
WemodifyCoyotte'salgorithm andfixT=20.
Wefindthatthealgorithm stoppedattime5:Coyote outpacedRoadrunnerandturned around.
Wechoosetheothercheckbox thatcorrespondstoafunction withvaluesinIR².
Nowthetimedidgoup to20andthevaluesofx,abscissaof Coyotearenolongermonotonic.
ThedisplayintheGeometrytabas aparametric curveshowsCoyote'schaoticbehavior.