ImageVerifierCode 换一换
格式:DOCX , 页数:23 ,大小:21.16KB ,
资源ID:10090626      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10090626.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(matlab中ode45函数编写.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

matlab中ode45函数编写.docx

1、matlab中ode45函数编写function varargout = ode45(ode,tspan,y0,options,varargin)%ODE45 Solve non-stiff differential equations, medium order method.% TOUT,YOUT = ODE45(ODEFUN,TSPAN,Y0) with TSPAN = T0 TFINAL integrates % the system of differential equations y = f(t,y) from time T0 to TFINAL % with initial c

2、onditions Y0. ODEFUN is a function handle. For a scalar T% and a vector Y, ODEFUN(T,Y) must return a column vector corresponding % to f(t,y). Each row in the solution array YOUT corresponds to a time % returned in the column vector TOUT. To obtain solutions at specific % times T0,T1,.,TFINAL (all in

3、creasing or all decreasing), use TSPAN = % T0 T1 . TFINAL. % % TOUT,YOUT = ODE45(ODEFUN,TSPAN,Y0,OPTIONS) solves as above with default% integration properties replaced by values in OPTIONS, an argument created% with the ODESET function. See ODESET for details. Commonly used options % are scalar rela

4、tive error tolerance RelTol (1e-3 by default) and vector% of absolute error tolerances AbsTol (all components 1e-6 by default).% If certain components of the solution must be non-negative, use% ODESET to set the NonNegative property to the indices of these% components.% % ODE45 can solve problems M(

5、t,y)*y = f(t,y) with mass matrix M that is% nonsingular. Use ODESET to set the Mass property to a function handle % MASS if MASS(T,Y) returns the value of the mass matrix. If the mass matrix % is constant, the matrix can be used as the value of the Mass option. If% the mass matrix does not depend on

6、 the state variable Y and the function% MASS is to be called with one input argument T, set MStateDependence to% none. ODE15S and ODE23T can solve problems with singular mass matrices. % TOUT,YOUT,TE,YE,IE = ODE45(ODEFUN,TSPAN,Y0,OPTIONS) with the Events% property in OPTIONS set to a function handle

7、 EVENTS, solves as above % while also finding where functions of (T,Y), called event functions, % are zero. For each function you specify whether the integration is % to terminate at a zero and whether the direction of the zero crossing % matters. These are the three column vectors returned by EVENT

8、S: % VALUE,ISTERMINAL,DIRECTION = EVENTS(T,Y). For the I-th event function: % VALUE(I) is the value of the function, ISTERMINAL(I)=1 if the integration % is to terminate at a zero of this event function and 0 otherwise. % DIRECTION(I)=0 if all zeros are to be computed (the default), +1 if only % zer

9、os where the event function is increasing, and -1 if only zeros where % the event function is decreasing. Output TE is a column vector of times % at which events occur. Rows of YE are the corresponding solutions, and % indices in vector IE specify which event occurred. % SOL = ODE45(ODEFUN,T0 TFINAL

10、,Y0.) returns a structure that can be% used with DEVAL to evaluate the solution or its first derivative at % any point between T0 and TFINAL. The steps chosen by ODE45 are returned % in a row vector SOL.x. For each I, the column SOL.y(:,I) contains % the solution at SOL.x(I). If events were detected

11、, SOL.xe is a row vector % of points at which events occurred. Columns of SOL.ye are the corresponding % solutions, and indices in vector SOL.ie specify which event occurred. % Example % t,y=ode45(vdp1,0 20,2 0); % plot(t,y(:,1);% solves the system y = vdp1(t,y), using the default relative error% to

12、lerance 1e-3 and the default absolute tolerance of 1e-6 for each% component, and plots the first component of the solution. % % Class support for inputs TSPAN, Y0, and the result of ODEFUN(T,Y):% float: double, single% See also % other ODE solvers: ODE23, ODE113, ODE15S, ODE23S, ODE23T, ODE23TB % im

13、plicit ODEs: ODE15I% options handling: ODESET, ODEGET% output functions: ODEPLOT, ODEPHAS2, ODEPHAS3, ODEPRINT% evaluating solution: DEVAL% ODE examples: RIGIDODE, BALLODE, ORBITODE% function handles: FUNCTION_HANDLE % NOTE: % The interpretation of the first input argument of the ODE solvers and % s

14、ome properties available through ODESET have changed in MATLAB 6.0.% Although we still support the v5 syntax, any new functionality is % available only with the new syntax. To see the v5 help, type in % the command line % more on, type ode45, more off % NOTE:% This portion describes the v5 syntax of

15、 ODE45.% T,Y = ODE45(F,TSPAN,Y0) with TSPAN = T0 TFINAL integrates the% system of differential equations y = F(t,y) from time T0 to TFINAL with% initial conditions Y0. F is a string containing the name of an ODE% file. Function F(T,Y) must return a column vector. Each row in% solution array Y corres

16、ponds to a time returned in column vector T. To% obtain solutions at specific times T0, T1, ., TFINAL (all increasing% or all decreasing), use TSPAN = T0 T1 . TFINAL.% % T,Y = ODE45(F,TSPAN,Y0,OPTIONS) solves as above with default% integration parameters replaced by values in OPTIONS, an argument% c

17、reated with the ODESET function. See ODESET for details. Commonly% used options are scalar relative error tolerance RelTol (1e-3 by% default) and vector of absolute error tolerances AbsTol (all% components 1e-6 by default).% % T,Y = ODE45(F,TSPAN,Y0,OPTIONS,P1,P2,.) passes the additional% parameters

18、 P1,P2,. to the ODE file as F(T,Y,FLAG,P1,P2,.) (see% ODEFILE). Use OPTIONS = as a place holder if no options are set.% % It is possible to specify TSPAN, Y0 and OPTIONS in the ODE file (see% ODEFILE). If TSPAN or Y0 is empty, then ODE45 calls the ODE file% TSPAN,Y0,OPTIONS = F(,init) to obtain any

19、values not supplied% in the ODE45 argument list. Empty arguments at the end of the call list% may be omitted, e.g. ODE45(F).% % ODE45 can solve problems M(t,y)*y = F(t,y) with a mass matrix M that is% nonsingular. Use ODESET to set Mass to M, M(t), or M(t,y) if the% ODE file is coded so that F(T,Y,m

20、ass) returns a constant,% time-dependent, or time- and state-dependent mass matrix, respectively.% The default value of Mass is none. ODE15S and ODE23T can solve problems% with singular mass matrices. % % T,Y,TE,YE,IE = ODE45(F,TSPAN,Y0,OPTIONS) with the Events property in% OPTIONS set to on, solves

21、 as above while also locating zero crossings% of an event function defined in the ODE file. The ODE file must be% coded so that F(T,Y,events) returns appropriate information. See% ODEFILE for details. Output TE is a column vector of times at which% events occur, rows of YE are the corresponding solu

22、tions, and indices in% vector IE specify which event occurred.% % See also ODEFILE % ODE45 is an implementation of the explicit Runge-Kutta (4,5) pair of% Dormand and Prince called variously RK5(4)7FM, DOPRI5, DP(4,5) and DP54.% It uses a free interpolant of order 4 communicated privately by% Dorman

23、d and Prince. Local extrapolation is done. % Details are to be found in The MATLAB ODE Suite, L. F. Shampine and% M. W. Reichelt, SIAM Journal on Scientific Computing, 18-1, 1997. % Mark W. Reichelt and Lawrence F. Shampine, 6-14-94% Copyright 1984-2009 The MathWorks, Inc.% $Revision: 5.74.4.10 $ $D

24、ate: 2009/04/21 03:24:15 $ solver_name = ode45; % Check inputsif nargin 4 options = ; if nargin 3 y0 = ; if nargin 2 tspan = ; if nargin 0); % t,y,. = odeXX(.)% There might be no output requested. sol = ; f3d = ; if output_sol sol.solver = solver_name; sol.extdata.odefun = ode; sol.extdata.options =

25、 options; sol.extdata.varargin = varargin; end % Handle solver argumentsneq, 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);n

26、fevals = nfevals + 1; % Handle the outputif nargout 0 outputFcn = odeget(options,OutputFcn,fast);else outputFcn = odeget(options,OutputFcn,odeplot,fast);endoutputArgs = ; if isempty(outputFcn) haveOutputFcn = false;else haveOutputFcn = true; outputs = odeget(options,OutputSel,1:neq,fast); if isa(out

27、putFcn,function_handle) % With MATLAB 6 syntax pass additional input arguments to outputFcn. outputArgs = varargin; end endrefine = max(1,odeget(options,Refine,4,fast);if ntspan 2 outputAt = RequestedPoints; % output only at tspan pointselseif refine 0 % non-trivial mass matrix Msingular = odeget(op

28、tions,MassSingular,no,fast); if strcmp(Msingular,maybe) warning(MATLAB:ode45:MassSingularAssumedNo,ODE45 assumes . MassSingular is no. See ODE15S or ODE23T.); elseif strcmp(Msingular,yes) error(MATLAB:ode45:MassSingularYes,. MassSingular cannot be yes for this solver. See ODE15S . or ODE23T.); end % Incorporate the mass matrix into odeFcn and odeArgs. odeFcn,odeArgs = odemassexplicit(FcnHandlesUsed,Mtype,odeFcn,odeArgs,Mfun,M); f0

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1