常微分方程数值解函数.docx
《常微分方程数值解函数.docx》由会员分享,可在线阅读,更多相关《常微分方程数值解函数.docx(16页珍藏版)》请在冰豆网上搜索。
常微分方程数值解函数
常微分方程数值解函数
ode23,ode45,ode113,ode15s,ode23s,ode23t,ode23tb
Solveinitialvalueproblemsforordinarydifferentialequations
Syntax
[T,Y]=solver(odefun,tspan,y0)
[T,Y]=solver(odefun,tspan,y0,options)
[T,Y,TE,YE,IE]=solver(odefun,tspan,y0,options)
sol=solver(odefun,[t0tf],y0...)
wheresolverisoneofode45,ode23,ode113,ode15s,ode23s,ode23t,orode23tb.
Arguments
Thefollowingtabledescribestheinputargumentstothesolvers.
odefun
Afunctionhandlethatevaluatestherightsideofthedifferentialequations.SeeFunctionHandlesintheMATLABProgrammingdocumentationformoreinformation.Allsolverssolvesystemsofequationsintheformorproblemsthatinvolveamassmatrix,.Theode23ssolvercansolveonlyequationswithconstantmassmatrices.ode15sandode23tcansolveproblemswithamassmatrixthatissingular,i.e.,differential-algebraicequations(DAEs).
tspan
Avectorspecifyingtheintervalofintegration,[t0,tf].Thesolverimposestheinitialconditionsattspan
(1),andintegratesfromtspan
(1)totspan(end).Toobtainsolutionsatspecifictimes(allincreasingoralldecreasing),usetspan=[t0,t1,...,tf].
Fortspanvectorswithtwoelements[t0tf],thesolverreturnsthesolutionevaluatedateveryintegrationstep.Fortspanvectorswithmorethantwoelements,thesolverreturnssolutionsevaluatedatthegiventimepoints.Thetimevaluesmustbeinorder,eitherincreasingordecreasing.
Specifyingtspanwithmorethantwoelementsdoesnotaffecttheinternaltimestepsthatthesolverusestotraversetheintervalfromtspan
(1)totspan(end).AllsolversintheODEsuiteobtainoutputvaluesbymeansofcontinuousextensionsofthebasicformulas.Althoughasolverdoesnotnecessarilysteppreciselytoatimepointspecifiedintspan,thesolutionsproducedatthespecifiedtimepointsareofthesameorderofaccuracyasthesolutionscomputedattheinternaltimepoints.
Specifyingtspanwithmorethantwoelementshaslittleeffectontheefficiencyofcomputation,butforlargesystems,affectsmemorymanagement.
y0
Avectorofinitialconditions.
options
Structureofoptionalparametersthatchangethedefaultintegrationproperties.Thisisthefourthinputargument.
[t,y]=solver(odefun,tspan,y0,options)
Youcancreateoptionsusingtheodesetfunction.Seeodesetfordetails.
Thefollowingtableliststheoutputargumentsforthesolvers.
T
Columnvectoroftimepoints.
Y
Solutionarray.EachrowinYcorrespondstothesolutionatatimereturnedinthecorrespondingrowofT.
TE
Thetimeatwhichaneventoccurs.
YE
Thesolutionatthetimeoftheevent.
IE
Theindexioftheeventfunctionthatvanishes.
sol
Structuretoevaluatethesolution.
Description
[T,Y]=solver(odefun,tspan,y0)withtspan=[t0tf]integratesthesystemofdifferentialequationsfromtimet0totfwithinitialconditionsy0.odefunisafunctionhandle.SeeFunctionHandlesintheMATLABProgrammingdocumentationformoreinformation.Functionf=odefun(t,y),forascalartandacolumnvectory,mustreturnacolumnvectorfcorrespondingto.EachrowinthesolutionarrayYcorrespondstoatimereturnedincolumnvectorT.Toobtainsolutionsatthespecifictimest0,t1,...,tf(allincreasingoralldecreasing),usetspan=[t0,t1,...,tf].
ParameterizingFunctions,intheMATLABMathematicsdocumentation,explainshowtoprovideadditionalparameterstothefunctionfun,ifnecessary.
[T,Y]=solver(odefun,tspan,y0,options)solvesasabovewithdefaultintegrationparametersreplacedbypropertyvaluesspecifiedinoptions,anargumentcreatedwiththeodesetfunction.CommonlyusedpropertiesincludeascalarrelativeerrortoleranceRelTol(1e-3bydefault)andavectorofabsoluteerrortolerancesAbsTol(allcomponentsare1e-6bydefault).Ifcertaincomponentsofthesolutionmustbenonnegative,usetheodesetfunctiontosettheNonNegativepropertytotheindicesofthesecomponents.Seeodesetfordetails.
[T,Y,TE,YE,IE]=solver(odefun,tspan,y0,options)solvesasabovewhilealsofindingwherefunctionsof,calledeventfunctions,arezero.Foreacheventfunction,youspecifywhethertheintegrationistoterminateatazeroandwhetherthedirectionofthezerocrossingmatters.Dothisbysettingthe'Events'propertytoafunction,e.g.,eventsor@events,andcreatingafunction[value,isterminal,direction]=events(t,y).Fortheitheventfunctioninevents,
value(i)isthevalueofthefunction.
isterminal(i)=1,iftheintegrationistoterminateatazeroofthiseventfunctionand0otherwise.
direction(i)=0ifallzerosaretobecomputed(thedefault),+1ifonlythezeroswheretheeventfunctionincreases,and-1ifonlythezeroswheretheeventfunctiondecreases.
CorrespondingentriesinTE,YE,andIEreturn,respectively,thetimeatwhichaneventoccurs,thesolutionatthetimeoftheevent,andtheindexioftheeventfunctionthatvanishes.
sol=solver(odefun,[t0tf],y0...)returnsastructurethatyoucanusewithdevaltoevaluatethesolutionatanypointontheinterval[t0,tf].Youmustpassodefunasafunctionhandle.Thestructuresolalwaysincludesthesefields:
sol.x
Stepschosenbythesolver.
sol.y
Eachcolumnsol.y(:
i)containsthesolutionatsol.x(i).
sol.solver
Solvername.
IfyouspecifytheEventsoptionandeventsaredetected,solalsoincludesthesefields:
sol.xe
Pointsatwhichevents,ifany,occurred.sol.xe(end)containstheexactpointofaterminalevent,ifany.
sol.ye
Solutionsthatcorrespondtoeventsinsol.xe.
sol.ie
IndicesintothevectorreturnedbythefunctionspecifiedintheEventsoption.Thevaluesindicatewhicheventthesolverdetected.
IfyouspecifyanoutputfunctionasthevalueoftheOutputFcnproperty,thesolvercallsitwiththecomputedsolutionaftereachtimestep.Fouroutputfunctionsareprovided:
odeplot,odephas2,odephas3,odeprint.Whenyoucallthesolverwithnooutputarguments,itcallsthedefaultodeplottoplotthesolutionasitiscomputed.odephas2andodephas3producetwo-andthree-dimensionalphaseplaneplots,respectively.odeprintdisplaysthesolutioncomponentsonthescreen.Bydefault,theODEsolverpassesallcomponentsofthesolutiontotheoutputfunction.YoucanpassonlyspecificcomponentsbyprovidingavectorofindicesasthevalueoftheOutputSelproperty.Forexample,ifyoucallthesolverwithnooutputargumentsandsetthevalueofOutputSelto[1,3],thesolverplotssolutioncomponents1and3astheyarecomputed.
Forthestiffsolversode15s,ode23s,ode23t,andode23tb,theJacobianmatrixiscriticaltoreliabilityandefficiency.UseodesettosetJacobianto@FJACifFJAC(T,Y)returnstheJacobianortothematrixiftheJacobianisconstant.IftheJacobianpropertyisnotset(thedefault),isapproximatedbyfinitedifferences.SettheVectorizedproperty'on'iftheODEfunctioniscodedsothatodefun(T,[Y1,Y2...])returns[odefun(T,Y1),odefun(T,Y2)...].Ifisasparsematrix,settheJPatternpropertytothesparsitypatternof,i.e.,asparsematrixSwithS(i,j)=1iftheithcomponentofdependsonthejthcomponentof,and0otherwise.
ThesolversoftheODEsuitecansolveproblemsoftheform,withtime-andstate-dependentmassmatrix.(Theode23ssolvercansolveonlyequationswithconstantmassmatrices.)Ifaproblemhasamassmatrix,createafunctionM=MASS(t,y)thatreturnsthevalueofthemassmatrix,anduseodesettosettheMasspropertyto@MASS.Ifthemassmatrixisconstant,thematrixshouldbeusedasthevalueoftheMassproperty.Problemswithstate-dependentmassmatricesaremoredifficult:
IfthemassmatrixdoesnotdependonthestatevariableandthefunctionMASSistobecalledwithoneinputargument,t,settheMStateDependencepropertyto'none'.
Ifthemassmatrixdependsweaklyon,setMStateDependenceto'weak'(thedefault);otherwise,setitto'strong'.Ineithercase,thefunctionMASSiscalledwiththetwoarguments(t,y).
Iftherearemanydifferentialequations,itisimportanttoexploitsparsity:
Returnasparse.
SupplythesparsitypatternofusingtheJPatternpropertyorasparseusingtheJacobianproperty.
Forstronglystate-dependent,setMvPatterntoasparsematrixSwithS(i,j)=1ifforanyk,the(i,k)componentofdependsoncomponentjof,and0otherwise.
Ifthemassmatrixissingular,thenisasystemofdifferentialalgebraicequations.DAEshavesolutionsonlywhenisconsistent,thatis,ifthereisavectorsuchthat.Theode15sandode23tsolverscansolveDAEsofindex1providedthaty0issufficientlyclosetobeingconsistent.Ifthereisamassmatrix,youcanuseodesettosettheMassSingularpropertyto'yes','no',or'maybe'.Thedefaultvalueof'maybe'causesthesolvertotestwhethertheproblemisaDAE.Youcanprovideyp0asthevalueoftheInitialSlopeproperty.Thedefaultisthezerovector.IfaproblemisaDAE,andy0andyp0arenotconsistent,thesolvertreatsthemasguesses,attemptstocomputeconsistentvaluesthatareclosetotheguesses,andcontinuestosolvetheproblem.WhensolvingDAEs,itisveryadvantageoustoformulatetheproblemsothatisadiagonalmatrix(asemi-explicitDAE).
Solver
ProblemType
OrderofAccuracy
WhentoUse
ode45
Nonstiff
Medium
Mostofthetime.Thisshouldbethefirstsolveryoutry.
ode23
Nonstiff
Low
Forproblemswithcrudeerrortolerancesorforsolvingmoderatelystiffproblems.
ode113
Nonstiff
Lowtohigh
Forproblemswithstringenterrortolerancesorforsolvingcomputationallyintensiveproblems.
ode15s
Stiff
Lowtomedium
Ifode45isslowbecausetheproblemisstiff.
ode23s
Stiff
Low
Ifusingcrudeerrortolerancestoso