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

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]

回答 (1 件)

Titus Edelhofer
Titus Edelhofer 2012 年 12 月 17 日

0 投票

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 件のコメント

Tonu
Tonu 2012 年 12 月 17 日
Hey thanks Titus for your reply, Can you further suggest me how to insert the 'events' in my code, my attempt fails.
THanks, Tonu

サインインしてコメントする。

カテゴリ

タグ

質問済み:

2012 年 12 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by