- #1
oby7842
- 11
- 0
Hii,
I am using 'OutputFcn' to check integration values after each step. Druing my solution I want to stop integration after I reach y<=0. Problem I am acing is that, after each iteration solver returns me array of y which is correspond to a array of t rather than at each point of t. Thats why I am able to stop my integration but not at the point wherey<=0 but after some point. My code is as follows,
function outfcn_test
tspan = [0:.05:3];
options=odeset('OutputFcn',@getvalues);
[t,y] = ode45(@myf,tspan,1,options);
plot(t,y)
function yprime = myf(t,y)
yprime = -y-5*exp(-t)*sin(5*t);
function status = getvalues(t,y,done)
if y>=0 status = 0;
else status =1;
end
I will appreciate any help in this regard. Thanks in advance.
I am using 'OutputFcn' to check integration values after each step. Druing my solution I want to stop integration after I reach y<=0. Problem I am acing is that, after each iteration solver returns me array of y which is correspond to a array of t rather than at each point of t. Thats why I am able to stop my integration but not at the point wherey<=0 but after some point. My code is as follows,
function outfcn_test
tspan = [0:.05:3];
options=odeset('OutputFcn',@getvalues);
[t,y] = ode45(@myf,tspan,1,options);
plot(t,y)
function yprime = myf(t,y)
yprime = -y-5*exp(-t)*sin(5*t);
function status = getvalues(t,y,done)
if y>=0 status = 0;
else status =1;
end
I will appreciate any help in this regard. Thanks in advance.