selectSolver
Description
s = selectSolver(
selects a solver for the F
,Name=Value
)ode
object
F
based on the parameters specified using one or more name-value
arguments and returns the solver name. Change the ode
object solver by
assigning the output of the selectSolver
function to the
Solver
property, for example, F.Solver =
selectSolver(F,DetectStiffness="on")
.
Examples
Detect Stiffness When Selecting ODE Solver
Create an ode
object for the van der Pol equations with mu = 1000
using the built-in function file vdp1000.m
. Specify the initial values of y'
and y''
as 2
and 0
, respectively.
F = ode(ODEFcn=@vdp1000,InitialValue=[2;0])
F = ode with properties: Problem definition ODEFcn: @vdp1000 InitialTime: 0 InitialValue: [2x1 double] EquationType: standard Solver properties AbsoluteTolerance: 1.0000e-06 RelativeTolerance: 1.0000e-03 Solver: auto SelectedSolver: ode45 Show all properties
The automatically selected solver is ode45
. Solve the ODE system over the time interval [0 3000]
. Measure the time the ode45
solver takes by using tic
and toc
.
tic sol45 = solve(F,0,3000); toc
Elapsed time is 11.110268 seconds.
Call the selectSolver
function with the DetectStiffness
name-value argument to choose a solver using a stiffness detection heuristic. Also specify the IntervalLength
name-value argument as 3000
.
F.Solver = selectSolver(F,DetectStiffness="on",IntervalLength=3000)
F = ode with properties: Problem definition ODEFcn: @vdp1000 InitialTime: 0 InitialValue: [2x1 double] Jacobian: [] EquationType: standard Solver properties AbsoluteTolerance: 1.0000e-06 RelativeTolerance: 1.0000e-03 Solver: ode15s Show all properties
The selected solver is now ode15s
. Solving the ODE system over the time interval [0 3000]
using the ode15s
solver is faster and more efficient than using the ode45
solver.
tic sol15s = solve(F,0,3000); toc
Elapsed time is 0.243462 seconds.
Input Arguments
F
— ODE problem to solve
ode
object
ODE problem to solve, specified as an ode
object.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: s = selectSolver(F,DetectStiffness="on")
DetectStiffness
— Stiffness detection heuristic
"off"
(default) | "on"
Stiffness detection heuristic, specified as "off"
or
"on"
. Specify DetectStiffness
as
"on"
to incorporate a stiffness detection heuristic when
selecting a solver.
If you do not know if the problem is stiff but want to account for potential
stiffness, specify the DetectStiffness
name-value argument as
"on"
. Otherwise, set the Solver
property of
the ode
object to:
"auto"
if you do not need to account for stiffness or only need to perform basic checks. For example, if you specify a Jacobian, then"auto"
will always return a stiff solver."stiff"
if you know the problem is stiff."nonstiff"
if you know the problem is not stiff.
Data Types: string
| char
IntervalLength
— Solver time interval
positive integer
Solver time interval, specified as a positive integer. The interval length is . You can use IntervalLength
to filter out
irrelevant timescales when selecting a solver.
The function ignores this argument when DetectStiffness
is
"off"
.
Version History
Introduced in R2024b
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)