ode45 where odefun requires more parameters
98 次查看(过去 30 天)
显示 更早的评论
My odefun.m has the following input structure:
function dy = odefun(t,y,a,b,c)
I want to use ode45 to integrate the ODE, but I need to see an example where the odefun takes in more than just t & y.
Please bear in mind that I've already read the following, and many more:
8. http://www.mathworks.com/matlabcentral/answers/47623-bugfixing-for-ode45-too-many-input-arguments
I've also read about arguments for function handles, "anonymous functions" and much more.
I believe that now it would be most constructive if someone could please just provide an example.
0 个评论
采纳的回答
Star Strider
2014-12-25
I’m not exactly certain what you’re actually asking, since my interpretation of your question is covered in the ode45 documentation. You haven’t listed the code for your ‘odefun’, or described what you want to do, so I’m guessing here.
If I understand correctly, what you want to do is a common way of passing extra parameters to your ODE function.
To use it with ode45, you only pass the ODE solver the ‘t’ and ‘y’ variables:
[t,y] = ode45(@(t,y) odefun(t,y,a,b,c), tspan, ic);
Note that ‘a’, ‘b’, and ‘c’ have to exist in your workspace.
3 个评论
Rik
2021-3-10
@(t,y) odefun(t,y,a,b,c)
This creates an anonymous function, with t and y as inputs. The values of the other variables are retrieved when the anonymous function is created:
y=1;
f=@(x) x+y;
y=3;
f(1)
更多回答(0 个)
另请参阅
类别
在 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!