Adding conditions / additional input to ode45 function
23 次查看(过去 30 天)
显示 更早的评论
Hello, I'm using ode45 and I want to be able to add an input ('i') which will determine a parameter in the function I put in the ode45:
[T,V] = ode45(@myfun,[0 20],vec_0);
and the function (shortened) is:
function dy = myfun(t,y)
dy=zeros(4,1);
if i==1
I_inj = 20;
elseif i==2
I_inj = 40;
% etc...
end
dy(1) = ...
dy(2) = ...
dy(3) = ...
dy(4) = ... + I_inj;
I've tried to add 'i' in the inputs of the function: function dy = hh(t,y,i) but I couldn't understand how to input 'i' in the ode45 function ( [T,V] = ode45(@myfun,[0 20],vec_0); ) I'll be happy to know how to do that or if there are other ways to set conditions to a function for ode45. Thanks a lot!
0 个评论
采纳的回答
Steven Lord
2017-5-2
While this documentation page uses fzero in its examples, the same techniques work for passing additional parameters into the ODE functions that you specify as the first input when you call ode45.
更多回答(1 个)
另请参阅
类别
在 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!