필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Tonu
Tonu 2012년 12월 17일
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일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by