Put a condition on 't' in ode15s ? Imp. question
1 次查看(过去 30 天)
显示 更早的评论
function F = zero_order(t,~)
global k st_t
a = 1/k ; % here k is an input
if t <= a ;
k = k;
else
k = 0;
end
F(1) = -k;
F(2) = k;
st_t =[st_t ; t a k];
F=F';
end
inital cond = [1 0];
The problem in the above code is that , as ode15s is adaptive time step, it gives output according to the time span I give to the equation i.e. according to the time step value just before the point when conditions change.
So say the time when k in the above code should be zero is at t=50 seconds. at that point, x(1) = 0 and x(2) = 1; but depending on the time step before the same. it calcultes and gives the output
x(1) = 0.8 and x(2) = 0.2;
and this values changes according to the time span I enter, at large t_span it gives me the correct values , while at lower time span size it gives me other values (not expected)
The crux of the question is : Is there a way by which I can insure that it calculates values at the given time i.e. t= 1/k in the above case.
Sorry if the question is not clear, Shall elaborate if required , Thanks, Tonu
0 个评论
回答(1 个)
Titus Edelhofer
2012-12-17
Hi,
yes, that's possible. It's the "event location property". Take a look at
doc odeset
and look there for "Events". Add 1/k as an event ...
Titus
另请参阅
类别
在 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!