﻿ Casyopee - Functions defined by an algorithm
You are here :   Home » Functions defined by an algorithm

# Functions defined by an algorithm

Forreference,seehere

• ExamplesinAnalysis
• TheEulermethodforan approximatesolutionofthedifferential equationy'=y
• Approximateanti-derivative
• FunctionswithvaluesinIR
• FunctionswithvaluesinIR²

## Examplesin Analysis

### TheEuler methodforan approximatesolutionofthedifferential equationy'=y

Inthisexample,thebasicsteps tocreateanduseafunctiondefined byanalgorithmaredemonstrated.

#### Theprogram

Awindowopenswithanembryonicprogram.

##### Structure

Wemodifyline3andchoose Repeatinthelistontheleft.

##### Declarations
Wechangethedeclarationofthevariable y.

Wereplace0by1theOK.

Wedeclareanewvariablep.

Weselecttheletterinthelistontheleftandweinitializelikefor y

##### LoopBody

WechoosetheentryAffect VariableintheLoop

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.

Wecheckthattheprogramrunscorrectly. Thevaluesofx,yandpinthe iterationaredisplayedin columns.
Wefillthecommentfieldto reminduswhatthefunction,thenOK tocreatethefunction.

#### Usingthefunction

Thefunctionappearsinthe listof  functionswiththecommentthatwehavechosen.
Abuttonwiththeletteralso appearsinthegraphic tab.Byactivatingthisbutton,the functionisgraphed.

Wecanchoosetodefinethe exponentialfunctionontheinterval[0, 2]andnotethat thecurvesaresuperimposed.

Wecanalsocreatethefunction f-g,toestimate thedifference.

Amessagewarnsthatthe function'suseislimitedtographics.

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.

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.

### Functionswith valuesinIR

TheCoyoteispostedat20 mdistancefromtheexitofatunnel.
Coyote'srocketallows himtohaveaspeedof3m.s-1.

#### Functionsdefiningthetrajectories

Wedefineaparameterfor theslopeofthetrajectoryof Coyoteandanother forthetraveltime.

Coyotte'strajectoryisthecurve ofthefunctioncdefinedby thefollowingalgorithm.

#### Usingthefunction

Oncethetwofunctionsandthe curvesarecreatedintheGeometry tabforagivenvalue ofaweanimatethe parameterT

Withaslopeof9/10coyote passesBeepBeep!Missed again.

### Functionswith valuesinIR²

WemodifyCoyotte'salgorithm andfixT=20.

Wechoosetheothercheckbox thatcorrespondstoafunction withvaluesinIR².

Nowthetimedidgoup to20andthevaluesofx,abscissaof Coyotearenolongermonotonic.

ThedisplayintheGeometrytabas showsCoyote'schaoticbehavior.

Creation date : 09/02/2016 - 19h41
Category : -