smart function to switch functions
2 次查看(过去 30 天)
显示 更早的评论
Suppose I want to tune different ode solvers to run:
ode23(@fun,...)
I want to use 'odesolver' so that
odesolver(@fun,...) actually runs ode23(@fun,...) when specifying odesolver=='ode23' and runs ode45(@fun,...) when specifying odesolver=='ode45'. Is there a smart way to do it?
0 个评论
采纳的回答
更多回答(2 个)
Anton Kogios
2024-4-28
You could set up a function with a switch statement, something like:
function odesolver(@fun,odesolverStr)
switch odesolverStr
case 'ode23'
ode23(@fun)
case 'ode45'
ode45(@fun)
otherwise
error('Incorrect ode solver specified.')
end
end
Steven Lord
2024-4-29
If you're using a sufficiently recent release (release R2023b or later) use the ode object and specify the Solver property to tell the object which ODE solver to use.
3 个评论
Steven Lord
2024-4-29
The ode object was introduced in release R2023b. It doesn't exist in earlier releases. There isn't a way to "automatically have MATLAB decide which ODE solver to call" in earlier releases.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!