Put a condition on 't' in ode15s ? Imp. question

1 vue (au cours des 30 derniers jours)
Tonu
Tonu le 17 Déc 2012
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
[Edited, Jan, code formatted]

Réponses (1)

Titus Edelhofer
Titus Edelhofer le 17 Déc 2012
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
  1 commentaire
Tonu
Tonu le 17 Déc 2012
Hey thanks Titus for your reply, Can you further suggest me how to insert the 'events' in my code, my attempt fails.
THanks, Tonu

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by