1、常微分方程数值解函数常微分方程数值解函数ode23, ode45, ode113, ode15s, ode23s, ode23t, ode23tbSolve initial value problems for ordinary differential equations SyntaxT,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,t0 tf,y0.)where solver i
2、s one of ode45, ode23, ode113, ode15s, ode23s, ode23t, or ode23tb.ArgumentsThe following table describes the input arguments to the solvers.odefunA function handle that evaluates the right side of the differential equations. See Function Handles in the MATLAB Programming documentation for more infor
3、mation. All solvers solve systems of equations in the form or problems that involve a mass matrix, . The ode23s solver can solve only equations with constant mass matrices. ode15s and ode23t can solve problems with a mass matrix that is singular, i.e., differential-algebraic equations (DAEs).tspanA
4、vector specifying the interval of integration, t0,tf. The solver imposes the initial conditions at tspan(1), and integrates from tspan(1) to tspan(end). To obtain solutions at specific times (all increasing or all decreasing), use tspan = t0,t1,.,tf.For tspan vectors with two elements t0 tf, the sol
5、ver returns the solution evaluated at every integration step. For tspan vectors with more than two elements, the solver returns solutions evaluated at the given time points. The time values must be in order, either increasing or decreasing. Specifying tspan with more than two elements does not affec
6、t the internal time steps that the solver uses to traverse the interval from tspan(1) to tspan(end). All solvers in the ODE suite obtain output values by means of continuous extensions of the basic formulas. Although a solver does not necessarily step precisely to a time point specified in tspan, th
7、e solutions produced at the specified time points are of the same order of accuracy as the solutions computed at the internal time points. Specifying tspan with more than two elements has little effect on the efficiency of computation, but for large systems, affects memory management.y0A vector of i
8、nitial conditions.optionsStructure of optional parameters that change the default integration properties. This is the fourth input argument.t,y = solver(odefun,tspan,y0,options)You can create options using the odeset function. See odeset for details.The following table lists the output arguments for
9、 the solvers.TColumn vector of time points.YSolution array. Each row in Y corresponds to the solution at a time returned in the corresponding row of T.TEThe time at which an event occurs.YEThe solution at the time of the event.IEThe index i of the event function that vanishes.solStructure to evaluat
10、e the solution.DescriptionT,Y = solver(odefun,tspan,y0) with tspan = t0 tf integrates the system of differential equations from time t0 to tf with initial conditions y0. odefun is a function handle. See Function Handles in the MATLAB Programming documentation for more information. Function f = odefu
11、n(t,y), for a scalar t and a column vector y, must return a column vector f corresponding to . Each row in the solution array Y corresponds to a time returned in column vector T. To obtain solutions at the specific times t0, t1,.,tf (all increasing or all decreasing), use tspan = t0,t1,.,tf. Paramet
12、erizing Functions, in the MATLAB Mathematics documentation, explains how to provide additional parameters to the function fun, if necessary.T,Y = solver(odefun,tspan,y0,options) solves as above with default integration parameters replaced by property values specified in options, an argument created
13、with the odeset function. Commonly used properties include a scalar relative error tolerance RelTol (1e-3 by default) and a vector of absolute error tolerances AbsTol (all components are 1e-6 by default). If certain components of the solution must be nonnegative, use the odeset function to set the N
14、onNegative property to the indices of these components. See odeset for details.T,Y,TE,YE,IE = solver(odefun,tspan,y0,options) solves as above while also finding where functions of , called event functions, are zero. For each event function, you specify whether the integration is to terminate at a ze
15、ro and whether the direction of the zero crossing matters. Do this by setting the Events property to a function, e.g., events or events, and creating a function value,isterminal,direction = events(t,y). For the ith event function in events,value(i) is the value of the function.isterminal(i) = 1, if
16、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 the zeros where the event function increases, and -1 if only the zeros where the event function decreases. Corresponding entries in TE, YE, and
17、 IE return, respectively, the time at which an event occurs, the solution at the time of the event, and the index i of the event function that vanishes.sol = solver(odefun,t0 tf,y0.) returns a structure that you can use with deval to evaluate the solution at any point on the interval t0,tf. You must
18、 pass odefun as a function handle. The structure sol always includes these fields:sol.xSteps chosen by the solver. sol.yEach column sol.y(:,i) contains the solution at sol.x(i).sol.solverSolver name.If you specify the Events option and events are detected, sol also includes these fields:sol.xePoints
19、 at which events, if any, occurred. sol.xe(end) contains the exact point of a terminal event, if any.sol.yeSolutions that correspond to events in sol.xe.sol.ieIndices into the vector returned by the function specified in the Events option. The values indicate which event the solver detected.If you s
20、pecify an output function as the value of the OutputFcn property, the solver calls it with the computed solution after each time step. Four output functions are provided: odeplot, odephas2, odephas3, odeprint. When you call the solver with no output arguments, it calls the default odeplot to plot th
21、e solution as it is computed. odephas2 and odephas3 produce two- and three-dimensional phase plane plots, respectively. odeprint displays the solution components on the screen. By default, the ODE solver passes all components of the solution to the output function. You can pass only specific compone
22、nts by providing a vector of indices as the value of the OutputSel property. For example, if you call the solver with no output arguments and set the value of OutputSel to 1,3, the solver plots solution components 1 and 3 as they are computed.For the stiff solvers ode15s, ode23s, ode23t, and ode23tb
23、, the Jacobian matrix is critical to reliability and efficiency. Use odeset to set Jacobian to FJAC if FJAC(T,Y) returns the Jacobian or to the matrix if the Jacobian is constant. If the Jacobian property is not set (the default), is approximated by finite differences. Set the Vectorized property on
24、 if the ODE function is coded so that odefun(T,Y1,Y2 .) returns odefun(T,Y1),odefun(T,Y2) . If is a sparse matrix, set the JPattern property to the sparsity pattern of , i.e., a sparse matrix S with S(i,j) = 1 if the ith component of depends on the jth component of , and 0 otherwise.The solvers of t
25、he ODE suite can solve problems of the form , with time- and state-dependent mass matrix . (The ode23s solver can solve only equations with constant mass matrices.) If a problem has a mass matrix, create a function M = MASS(t,y) that returns the value of the mass matrix, and use odeset to set the Ma
26、ss property to MASS. If the mass matrix is constant, the matrix should be used as the value of the Mass property. Problems with state-dependent mass matrices are more difficult: If the mass matrix does not depend on the state variable and the function MASS is to be called with one input argument, t,
27、 set the MStateDependence property to none. If the mass matrix depends weakly on , set MStateDependence to weak (the default); otherwise, set it to strong. In either case, the function MASS is called with the two arguments (t,y). If there are many differential equations, it is important to exploit s
28、parsity: Return a sparse . Supply the sparsity pattern of using the JPattern property or a sparse using the Jacobian property. For strongly state-dependent , set MvPattern to a sparse matrix S with S(i,j) = 1 if for any k, the (i,k) component of depends on component j of , and 0 otherwise. If the ma
29、ss matrix is singular, then is a system of differential algebraic equations. DAEs have solutions only when is consistent, that is, if there is a vector such that . The ode15s and ode23t solvers can solve DAEs of index 1 provided that y0 is sufficiently close to being consistent. If there is a mass m
30、atrix, you can use odeset to set the MassSingular property to yes, no, or maybe. The default value of maybe causes the solver to test whether the problem is a DAE. You can provide yp0 as the value of the InitialSlope property. The default is the zero vector. If a problem is a DAE, and y0 and yp0 are
31、 not consistent, the solver treats them as guesses, attempts to compute consistent values that are close to the guesses, and continues to solve the problem. When solving DAEs, it is very advantageous to formulate the problem so that is a diagonal matrix (a semi-explicit DAE).SolverProblem TypeOrder
32、of AccuracyWhen to Useode45NonstiffMediumMost of the time. This should be the first solver you try.ode23NonstiffLowFor problems with crude error tolerances or for solving moderately stiff problems.ode113NonstiffLow to highFor problems with stringent error tolerances or for solving computationally intensive problems.ode15sStiffLow to mediumIf ode45 is slow because the problem is stiff.ode23sStiffLowIf using crude error tolerances to so
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1