필터 지우기
필터 지우기

Thresholds in ODE solvers

조회 수: 3 (최근 30일)
Francisco de Castro
Francisco de Castro 2011년 5월 18일
Working with models of ecological communities based on diff. equations, I want to define a extinction threshold. If, during the simulation, any species density drops below that it should go directly to zero. I do it with a line in the equations file like:
x(x < threshold)= 0;
But it's not working. As a simple example see this:
function dn= expdecay(t,x)
dn= zeros(1,1);
dn= -0.1*x;
x(x<10)= 0;
When I call: [t,x]= ode45('expdecay',[1 100],[100]); plot(t,x)
I'd expect a straight drop to zero when x= 10, but it doesn't happen. Any idea how to implement this?

채택된 답변

Teja Muppirala
Teja Muppirala 2011년 5월 19일
Make your expdecay look something like this:
dn= zeros(1,1);
dn= -0.1*x;
dead = x < 10;
assignin('caller','dead',dead);
evalin('caller','y(dead) = 0;');
  댓글 수: 2
Teja Muppirala
Teja Muppirala 2011년 5월 19일
This line is not needed: dn= zeros(1,1);
Francisco de Castro
Francisco de Castro 2011년 5월 19일
Worked beautifully

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

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 5월 18일
Your function is returning dn. x isn't passed back so the last line doesn't do anything...

카테고리

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