Put a condition on 't' in ode15s ? Imp. question
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
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
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!