问题
EDITED: Thanks for upvotes, now i finally added images. Added full m.file, although i don't think it wass necessary. The key of the code is.
xp(2)=...-((x(2)>=X2)&(xp(3)>=0)...;
xp(3)=...-((x(3)>=X3)&(xp(2)>=0))...;
Full code:
function xp=uzdevums1(t,x)
%parametr values
r1 = 0.1; r2 = 1; r3 = 0.2;
K1=100;K2 = 100; K3 = 100;
X2=25;X3=10;
speedx2 = 0.02; speedx3=0.02;
%ode system
xp=zeros(3,1);
xp(1)=r1*(1-x(1)/(x(2)+x(3)))*x(1);
xp(2)=r2*(1-x(2)/K2)*x(2)-((x(2)>=X2)&(xp(3)>=0)&xp(1)>0)*x(2)*x(1)*speedx2;
xp(3)=r3*(1-x(3)/K3)*x(3)-((x(3)>=X3)&(xp(2)>=0))*x(3)*x(1)*speedx3;
from shell: [T,X]=ode45('uzdevums1',[0 60],[10 80 20]); The idea is that boolean expression in xp(2) (derivative of green line) should be true until it approaches X2=25, but boolean expression for xp(3) (derivative of red line) should be false until xp(2) changes sign.
Red line = x3 does fine.. as the sign for xp(2) changes, boolean epxression is now true and red line changes direction, but green line fails to do so... in other words both x(2)>=X2 (which is fine) and xp(3)>=0 (which i don't understand)
in other words: red line is falling, how comes xp(3)>=0 ?
In 2nd picture i added xp(1)>0 and boolean expression finally become false... but why not at as xp(3) changed sign?!
Thanks
回答1:
If I understand you correctly, the main thing you want help with is an explanation of why the statement xp(3)>=0
evaluates to true.
Study your calculations of xp
step-by-step.
xp=zeros(3,1);
xp(1)=r1*(1-x(1)/(x(2)+x(3)))*x(1);
xp(2)=r2*(1-x(2)/K2)*x(2)-((x(2)>=X2)&(xp(3)>=0)&xp(1)>0)*x(2)*x(1)*speedx2;
xp(3)=r3*(1-x(3)/K3)*x(3)-((x(3)>=X3)&(xp(2)>=0))*x(3)*x(1)*speedx3;
You try to use the value of xp(3)
when you calculate xp(2)
(and vice versa). But xp(3)
is still zero when you use it in the calculation of xp(2), so the expression xp(3)>=0
will always evaluate to true.
来源:https://stackoverflow.com/questions/14173377/matlab-tricky-ode-system-with-boolean