matlab中ode45函数编写文档格式.docx

上传人:b****2 文档编号:6038872 上传时间:2023-05-05 格式:DOCX 页数:23 大小:21.16KB
下载 相关 举报
matlab中ode45函数编写文档格式.docx_第1页
第1页 / 共23页
matlab中ode45函数编写文档格式.docx_第2页
第2页 / 共23页
matlab中ode45函数编写文档格式.docx_第3页
第3页 / 共23页
matlab中ode45函数编写文档格式.docx_第4页
第4页 / 共23页
matlab中ode45函数编写文档格式.docx_第5页
第5页 / 共23页
matlab中ode45函数编写文档格式.docx_第6页
第6页 / 共23页
matlab中ode45函数编写文档格式.docx_第7页
第7页 / 共23页
matlab中ode45函数编写文档格式.docx_第8页
第8页 / 共23页
matlab中ode45函数编写文档格式.docx_第9页
第9页 / 共23页
matlab中ode45函数编写文档格式.docx_第10页
第10页 / 共23页
matlab中ode45函数编写文档格式.docx_第11页
第11页 / 共23页
matlab中ode45函数编写文档格式.docx_第12页
第12页 / 共23页
matlab中ode45函数编写文档格式.docx_第13页
第13页 / 共23页
matlab中ode45函数编写文档格式.docx_第14页
第14页 / 共23页
matlab中ode45函数编写文档格式.docx_第15页
第15页 / 共23页
matlab中ode45函数编写文档格式.docx_第16页
第16页 / 共23页
matlab中ode45函数编写文档格式.docx_第17页
第17页 / 共23页
matlab中ode45函数编写文档格式.docx_第18页
第18页 / 共23页
matlab中ode45函数编写文档格式.docx_第19页
第19页 / 共23页
matlab中ode45函数编写文档格式.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

matlab中ode45函数编写文档格式.docx

《matlab中ode45函数编写文档格式.docx》由会员分享,可在线阅读,更多相关《matlab中ode45函数编写文档格式.docx(23页珍藏版)》请在冰点文库上搜索。

matlab中ode45函数编写文档格式.docx

Mass'

propertytoafunctionhandle

%MASSifMASS(T,Y)returnsthevalueofthemassmatrix.Ifthemassmatrix

%isconstant,thematrixcanbeusedasthevalueofthe'

option.If

%themassmatrixdoesnotdependonthestatevariableYandthefunction

%MASSistobecalledwithoneinputargumentT,set'

MStateDependence'

to

%'

none'

.ODE15SandODE23Tcansolveproblemswithsingularmassmatrices.

%

%[TOUT,YOUT,TE,YE,IE]=ODE45(ODEFUN,TSPAN,Y0,OPTIONS)withthe'

Events'

%propertyinOPTIONSsettoafunctionhandleEVENTS,solvesasabove

%whilealsofindingwherefunctionsof(T,Y),calledeventfunctions,

%arezero.Foreachfunctionyouspecifywhethertheintegrationis

%toterminateatazeroandwhetherthedirectionofthezerocrossing

%matters.ThesearethethreecolumnvectorsreturnedbyEVENTS:

%[VALUE,ISTERMINAL,DIRECTION]=EVENTS(T,Y).FortheI-theventfunction:

%VALUE(I)isthevalueofthefunction,ISTERMINAL(I)=1iftheintegration

%istoterminateatazeroofthiseventfunctionand0otherwise.

%DIRECTION(I)=0ifallzerosaretobecomputed(thedefault),+1ifonly

%zeroswheretheeventfunctionisincreasing,and-1ifonlyzeroswhere

%theeventfunctionisdecreasing.OutputTEisacolumnvectoroftimes

%atwhicheventsoccur.RowsofYEarethecorrespondingsolutions,and

%indicesinvectorIEspecifywhicheventoccurred.

%SOL=ODE45(ODEFUN,[T0TFINAL],Y0...)returnsastructurethatcanbe

%usedwithDEVALtoevaluatethesolutionoritsfirstderivativeat

%anypointbetweenT0andTFINAL.ThestepschosenbyODE45arereturned

%inarowvectorSOL.x.ForeachI,thecolumnSOL.y(:

I)contains

%thesolutionatSOL.x(I).Ifeventsweredetected,SOL.xeisarowvector

%ofpointsatwhicheventsoccurred.ColumnsofSOL.yearethecorresponding

%solutions,andindicesinvectorSOL.iespecifywhicheventoccurred.

%Example

%[t,y]=ode45(@vdp1,[020],[20]);

%plot(t,y(:

1));

%solvesthesystemy'

=vdp1(t,y),usingthedefaultrelativeerror

%tolerance1e-3andthedefaultabsolutetoleranceof1e-6foreach

%component,andplotsthefirstcomponentofthesolution.

%ClasssupportforinputsTSPAN,Y0,andtheresultofODEFUN(T,Y):

%float:

double,single

%Seealso

%otherODEsolvers:

ODE23,ODE113,ODE15S,ODE23S,ODE23T,ODE23TB

%implicitODEs:

ODE15I

%optionshandling:

ODESET,ODEGET

%outputfunctions:

ODEPLOT,ODEPHAS2,ODEPHAS3,ODEPRINT

%evaluatingsolution:

DEVAL

%ODEexamples:

RIGIDODE,BALLODE,ORBITODE

%functionhandles:

FUNCTION_HANDLE

%NOTE:

%TheinterpretationofthefirstinputargumentoftheODEsolversand

%somepropertiesavailablethroughODESEThavechangedinMATLAB6.0.

%Althoughwestillsupportthev5syntax,anynewfunctionalityis

%availableonlywiththenewsyntax.Toseethev5help,typein

%thecommandline

%moreon,typeode45,moreoff

%Thisportiondescribesthev5syntaxofODE45.

%[T,Y]=ODE45('

F'

TSPAN,Y0)withTSPAN=[T0TFINAL]integratesthe

%systemofdifferentialequationsy'

=F(t,y)fromtimeT0toTFINALwith

%initialconditionsY0.'

isastringcontainingthenameofanODE

%file.FunctionF(T,Y)mustreturnacolumnvector.Eachrowin

%solutionarrayYcorrespondstoatimereturnedincolumnvectorT.To

%obtainsolutionsatspecifictimesT0,T1,...,TFINAL(allincreasing

%oralldecreasing),useTSPAN=[T0T1...TFINAL].

TSPAN,Y0,OPTIONS)solvesasabovewithdefault

%integrationparametersreplacedbyvaluesinOPTIONS,anargument

%createdwiththeODESETfunction.SeeODESETfordetails.Commonly

%usedoptionsarescalarrelativeerrortolerance'

(1e-3by

%default)andvectorofabsoluteerrortolerances'

(all

%components1e-6bydefault).

TSPAN,Y0,OPTIONS,P1,P2,...)passestheadditional

%parametersP1,P2,...totheODEfileasF(T,Y,FLAG,P1,P2,...)(see

%ODEFILE).UseOPTIONS=[]asaplaceholderifnooptionsareset.

%ItispossibletospecifyTSPAN,Y0andOPTIONSintheODEfile(see

%ODEFILE).IfTSPANorY0isempty,thenODE45callstheODEfile

%[TSPAN,Y0,OPTIONS]=F([],[],'

init'

)toobtainanyvaluesnotsupplied

%intheODE45argumentlist.Emptyargumentsattheendofthecalllist

%maybeomitted,e.g.ODE45('

).

=F(t,y)withamassmatrixMthatis

%nonsingular.UseODESETtosetMassto'

M'

'

M(t)'

or'

M(t,y)'

ifthe

%ODEfileiscodedsothatF(T,Y,'

mass'

)returnsaconstant,

%time-dependent,ortime-andstate-dependentmassmatrix,respectively.

%ThedefaultvalueofMassis'

.ODE15SandODE23Tcansolveproblems

%withsingularmassmatrices.

%[T,Y,TE,YE,IE]=ODE45('

TSPAN,Y0,OPTIONS)withtheEventspropertyin

%OPTIONSsetto'

on'

solvesasabovewhilealsolocatingzerocrossings

%ofaneventfunctiondefinedintheODEfile.TheODEfilemustbe

%codedsothatF(T,Y,'

events'

)returnsappropriateinformation.See

%ODEFILEfordetails.OutputTEisacolumnvectoroftimesatwhich

%eventsoccur,rowsofYEarethecorrespondingsolutions,andindicesin

%vectorIEspecifywhicheventoccurred.

%SeealsoODEFILE

%ODE45isanimplementationoftheexplicitRunge-Kutta(4,5)pairof

%DormandandPrincecalledvariouslyRK5(4)7FM,DOPRI5,DP(4,5)andDP54.

%Itusesa"

free"

interpolantoforder4communicatedprivatelyby

%DormandandPrince.Localextrapolationisdone.

%DetailsaretobefoundinTheMATLABODESuite,L.F.Shampineand

%M.W.Reichelt,SIAMJournalonScientificComputing,18-1,1997.

%MarkW.ReicheltandLawrenceF.Shampine,6-14-94

%Copyright1984-2009TheMathWorks,Inc.

%$Revision:

5.74.4.10$$Date:

2009/04/2103:

24:

15$

solver_name='

ode45'

;

%Checkinputs

ifnargin<

4

options=[];

ifnargin<

3

y0=[];

2

tspan=[];

1

error('

MATLAB:

ode45:

NotEnoughInputs'

...

'

Notenoughinputarguments.SeeODE45.'

);

end

end

end

%Stats

nsteps=0;

nfailed=0;

nfevals=0;

%Output

FcnHandlesUsed=isa(ode,'

function_handle'

output_sol=(FcnHandlesUsed&

&

(nargout==1));

%sol=odeXX(...)

output_ty=(~output_sol&

(nargout>

0));

%[t,y,...]=odeXX(...)

%Theremightbenooutputrequested...

sol=[];

f3d=[];

ifoutput_sol

sol.solver=solver_name;

sol.extdata.odefun=ode;

sol.extdata.options=options;

sol.extdata.varargin=varargin;

end

%Handlesolverarguments

[neq,tspan,ntspan,next,t0,tfinal,tdir,y0,f0,odeArgs,odeFcn,...

options,threshold,rtol,normcontrol,normy,hmax,htry,htspan,dataType]=...

odearguments(FcnHandlesUsed,solver_name,ode,tspan,y0,options,varargin);

nfevals=nfevals+1;

%Handletheoutput

ifnargout>

0

outputFcn=odeget(options,'

OutputFcn'

[],'

fast'

else

@odeplot,'

outputArgs={};

ifisempty(outputFcn)

haveOutputFcn=false;

haveOutputFcn=true;

outputs=odeget(options,'

OutputSel'

1:

neq,'

ifisa(outputFcn,'

%WithMATLAB6syntaxpassadditionalinputargumentstooutputFcn.

outputArgs=varargin;

refine=max(1,odeget(options,'

Refine'

4,'

));

ifntspan>

outputAt='

RequestedPoints'

%outputonlyattspanpoints

elseifrefine<

=1

SolverSteps'

%computedpoints,norefinement

RefinedSteps'

%computedpoints,withrefinement

S=(1:

refine-1)/refine;

printstats=strcmp(odeget(options,'

Stats'

'

off'

),'

%Handletheeventfunction

[haveEventFcn,eventFcn,eventArgs,valt,teout,yeout,ieout]=...

odeevents(FcnHandlesUsed,odeFcn,t0,y0,options,varargin);

%Handlethemassmatrix

[Mtype,M,Mfun]=odemass(FcnHandlesUsed,odeFcn,t0,y0,options,varargin);

ifMtype>

0%non-trivialmassmatrix

Msingular=odeget(options,'

MassSingular'

no'

ifstrcmp(Msingular,'

maybe'

warning('

MassSingularAssumedNo'

['

ODE45assumes'

...

MassSingularis'

'

.SeeODE15SorODE23T.'

]);

elseifstrcmp(Msingular,'

yes'

MassSingularYes'

['

MassSingularcannotbe'

forthissolver.SeeODE15S'

...

orODE23T.'

%IncorporatethemassmatrixintoodeFcnandodeArgs.

[odeFcn,odeArgs]=odemassexplicit(FcnHandlesUsed,Mtype,odeFcn,odeArgs,Mfun,M);

f0

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2