Using odesolver with functions that have many inputs
5 次查看(过去 30 天)
显示 更早的评论
I'm trying to use ode45 to integrate a first order differential equation. The first line of my function m-file is
function dEds = dPdE(s, E, U0, H0, mu, T, t, initial, final,timestep)
s is my independent variable, and E(s) is what I am solving for. All the other variables are matrices or scalars, and are used in the m-file. My question is, when using ode45, how do I specify these other variables? On this page
other inputs are being put in after the (blank) options, and I verified for myself that it can work, but I haven't seen any documentation refer to that. Furthermore it doesn't seem to be working when I try and solve my equation:
[s E]=ode45(@dPdE,[0 5],E(321),[],U0,H0,mu,5,3.2,2,3,.01);
It says too many input arguments. How can I make this go?
(A more trivial question I have is whether I need to put s as an input argument if the function never uses it.)
0 个评论
采纳的回答
Andrew Newell
2011-6-10
The documentation in the link you provide probably applies to an older version of MATLAB than you have. Instead, create an anonymous function:
f = @(s,E) dPdE(s, E, U0, H0, mu, T, t, initial, final,timestep);
Then you can solve the equation using
[s, E]=ode45(f,[0 5],E(321));
Yes, you do need to provide s as an input argument.
更多回答(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!