Preben Alsholm

13743 Reputation

22 Badges

21 years, 118 days

MaplePrimes Activity


These are replies submitted by Preben Alsholm

@aureux Since I don't know your project and to what depth you are dipping into the questions of sustainability (a much overused term) I may have made the mistake of making this whole thing look more difficult than it is.

If you only want to see what actually happens for the parameters given and for the initial condition given then you need only do the following.

(I take for granted that when you wrote t=40 you meant t=0. The system is autonomous so the starting value for t may as well be 0. Anything else is just confusing.)

restart;
sys:=D(x)(t)=a*x(t)-a*x(t)^2/k-b*x(t)*y(t), D(y)(t) = -beta*y(t)+c*x(t)*y(t);
params:=[a = .71780, beta = .3067, b = 0.2072e-1, c = 0.9e-4, k = 17000];
sol:=dsolve({eval(sys,params),x(0)=6000,y(0)=40},numeric);
plots:-odeplot(sol,[[t,x(t)],[t,100*y(t)]],0..100,size=[1000,300]); #Notice 100*y
sol(100);

################## Continuing with the dimensionless version ###########
However, if you would like to see how to get the same result from SYS in the previous exchange then continue from there with

eqs:={X=k/(a*T),T=1/beta,Y=beta/b,k=(a/c)*A,a=B*beta};
params:=solve(eqs,{T,X,Y,A,B});

paramsConc:=[a = .71780, beta = .3067, b = 0.2072e-1, c = 0.9e-4, k = 17000];
ABTXY:=eval(params,paramsConc);
#Here I include initial values for u and v as parameters:
res:=dsolve({SYS,u(0)=u0,v(0)=v0},numeric,parameters=[u0,v0,A,B]);
#The parameters in the present concrete case:
L:=subs(ABTXY,[6000/X,40/Y,A,B]); #x(0)=6000, y(0)=40.
#Setting the parameters:
res(parameters=L);
#Readying input for odeplot so that it actually plots x and y although as functions of tau:
input:=subs(ABTXY,[ [[tau,X*u(tau)],[tau,100*Y*v(tau)]],tau=0..100/T]); #Notice 100*y
plots:-odeplot(res,op(input),size=[1000,300]);
###########Appearing as functions of t ######
##You can change the tickmarks and the labels to make the graphs look like graphs of x(t) and 100*y(t) like this:
input:=subs(ABTXY,[ [[tau,X*u(tau)],[tau,100*Y*v(tau)]],tau=0..100/T,
          tickmarks=[[seq(i*10/T=i*10,i=0..10)],default]]);
plots:-odeplot(res,op(input),labels=["t","x,100*y"],size=[1000,300]);






@THAPELO Noticing the exponential behavior of A and wanting to compute the values that I1,I2,I3,I4,S approach at infinity, I tried replacing A(t) by AE(t) = exp(-(mu+mu)*t)*A(t) for convenience.

Because of the long exchange, for the sake of clarity I paste the full code:

restart;
Digits:=15:
Sys1:=diff(S(t),t)=(1-h0)*Lambda1-(b*(I1(t)+phi1*I2(t)+phi2*I3(t))/N(t)+mu)*S(t);
Sys2:=diff(I1(t),t)=h1*Lambda1-(b*(I1(t)+phi1*I2(t)+phi2*I3(t))/N(t))*S(t)-(mu+rho+delta)*I1(t);
Sys3:=diff(I2(t),t)=h2* Lambda1+f*delta*I1(t)-(mu+theta+delta)*I2(t);
Sys4:=diff(I3(t),t)=h3*Lambda1+(1-f)*delta*I1(t)-(mu+theta+delta)*I3(t);
Sys5:=diff(I4(t),t)=h4*Lambda1+theta*(I2(t)+I3(t))-(mu+rho)*I4(t); ########* after theta
Sys6:=diff(A(t),t)=rho*(I1(t)+I2(t)+I3(t)+I4(t))+(mu+nu)*A(t); #minus? at the last term?
PDEtools:-dchange({A(t)=exp((mu+nu)*t)*AE(t)},Sys6,[AE]);
Sys6E:=combine(isolate(%,diff(AE(t),t)));
## Notice that the system ({Sys1,Sys2,Sys3,Sys4,Sys5,Sys6E} is no longer autonomous.
# Parameters
params:={Lambda1=0.029,b=0.5,phi1=0.25,phi2=1.01,mu=0.02,rho=0.1,delta=0.1,
  f=0.85,theta=0.2,nu=0.33,h0=0.4,h1=0.08,h2=0.02,h3=0.06,h4=0.4};
paramsE:=params union {subs(params,N(t)=S(t)+I1(t)+I2(t)+I3(t)+I4(t)+AE(t)*exp((mu+nu)*t))};
SYSE:=eval({Sys1,Sys2,Sys3,Sys4,Sys5,Sys6E},paramsE);
##Notice that AE(0)=A(0), so AE(0)=15.
Soln:=dsolve(SYSE union {S(0)=65,I1(0)=25,I2(0)=20,I3(0)=30,I4(0)=35,AE(0)=15},numeric);
vars:=[AE, I1, I2, I3, I4, S];
plots:-odeplot(Soln,[seq([t,v(t)],v=vars)],t=0..100,legend=vars,size=[1000,300],thickness=3);
#### We now try to find the values that AE, I1, I2, I3, I4, S seem to approach by other means than through Soln
#Since N(t)-> infinity as t -> infinity we do:
eval([Sys1,Sys2,Sys3,Sys4,Sys5],N(t)=infinity);
evalindets(%,function,s->op(0,s));
solve(%,vars[2..6]);
eval(%,params);
subs(Soln(500),vars[2..6]=~vars[2..6](t));
## Notice the perfect agreement except for S which is close though.
## The reason is that S(t) decreases rather slowly towards its value at infinity, as exp(-mu*):
#We look at that
eval(Sys1,N(t)=infinity);
dsolve(%);
eval(%,params);
plots:-odeplot(Soln,[t,ln(S(t)-0.87)],t=100..200);
#The slope ought to be -mu = -1/50 which appears correct.

@THAPELO Please notice that I edited the reply above.

@THAPELO Substituting parameters first helps make the two solutions look much less complicated:

Although not necessary for solve I use the opportunity to replace A(t) by A, I1(t) by I1, etc. by the use of evalindets:

eqs:=evalindets( eval(rhs~({Sys1,Sys2,Sys3,Sys4,Sys5,Sys6}),params),function,x->op(0,x));
solve(eqs,{A,S,I1,I2,I3,I4});

pts:=map(subs,[%],[A,S,I1,I2,I3,I4]); #lower case m in map.

You got 2 equilibrium points none of which consists entirely of nonnegative values. Irrelevant?

However, notice that A(t) grows exponentially with t as exp((mu+nu)*t) in fact.

But the other functions appear to approach positive values as t -> infinity. Try plotting those only (i.e. don't include A(t)).





 

@aureux A and B are given by params as found above (now with g=0) . Thus if the original parameters a,b,c, ... are given, then A and B are determined. But during an investigation of the properties of the system (with a,b,c,.. not given) you can give them any value consistent with the assumptions made in the change of variables: a,b,k,beta all positive. The assumption c>=0 has nothing to do with that, but the wolves are sure going to die out if they don't profit from eating elk.
That implies A>=0 and B>0.


@aureux That looks good to me.

The advantage of making this change of variables from x,y,t to u,v,tau is that examining a system with only 2 parameters is easier than examining one with (now) 5 parameters.
The point being that the behaviors of sys and SYS are the same. Thus if you find that SYS has 3 equilibrium points, so does sys, and you can find the ones from the others.
The stability properties of those equilibrium points are the same: If the equilibrium point in the open first quadrant for SYS is asymptotically stable and a spiral point, so is the corresponding point for sys, etc.
After all (I guess) the question is: is the grey wolf - elk 'situation' in Yellowstone Park going to end in both species dying out, one of the two dying out, or can they coexist (not peacefully of course)?

@aureux Often people introduce dimensionless variables mostly because this usually will reduce the number of parameter (constants).
There is no unique way of doing this. I indicate a method below that uses dchange from the PDEtools package.
I replaced alpha with a, but otherwise didn't change names of constant in sys below.

The idea is make the substitutions x(t)= X*u(tau),y(t)=Y*v(tau), t=T*tau  thereby introducing also a new time tau. The 3 constants X,Y,T should be chosen so as to reduce the number of parameters. After all you have a,b,c,k,g,beta, i.e. 6 constants.
You can reduce that number to 2.
Suppose all your 6 parameters are nonnegative by assumption and suppose further that a>0, b>0, k>0, beta+g > 0, then the changes actually made below make sense. By that I mean that you don't want X,Y, or T to be zero (or negative even).

sys:=D(x)(t)=a*x(t)-a*x(t)^2/k-b*x(t)*y(t)-g*x(t), D(y)(t) = -beta*y(t)+c*x(t)*y(t)-g*y(t);

PDEtools:-dchange({x(t)=X*u(tau),y(t)=Y*v(tau),t=T*tau},{sys},[tau,u,v]);

solve(%,{diff(u(tau),tau),diff(v(tau),tau)});
SYS1:=collect(%,[u,v],distributed,factor);
## Now you can choose the constants X,Y,T the way you wish
## I did as follows
eval(SYS1,X=k/(a*T)); #Here you use that a>0 and k>0
eval(%,T=1/(beta+g)); #Here you use that beta+g>0
eval(%,Y=(beta+g)/b); #Here you use that b>0 and beta+g>0
eval(%,k=(a/c)*A); #Actually just introducing a simplifying parameter A
SYS:=op(eval(%,a-g=B*(beta+g))); # Introducing a simplifying parameter B
#The replacements made:
eqs:={X=k/(a*T),T=1/(beta+g),Y=(beta+g)/b,k=(a/c)*A,a-g=B*(beta+g)};
## To be able to get back and forth between sys and SYS we need these:
params:=solve(eqs,{T,X,Y,A,B});

From our assumptions it follows that A>=0, but B is just real.

@Yiannis Galidakis What do you want to happen here?

plot3d(x^2+y^2,x=-1..1,y=-1..1); p1:=%:
plot3d(x^2+y^2,x=-2..2,y=-2..2); p2:=%:
plots:-display(p1,p2,insequence);

########

Something like this?

f:=(x,y)->x^2+y^2;
plot3d(f,-1..1,-1..1); p1:=%:
plot3d((x,y)->f(x*2,y*2),-1..1,-1..1); p2:=%:
plots:-display(p1,p2,insequence);

@THAPELO There are a few misspellings and one syntax error:

(1) phi1 is spelled as ph1 in params.

(2) Sys1, Sys2 etc. are spelled sys1,sy2 in dsolve.

(4) a multiplication sign is missing in Sys5 right after theta.

Besides that you obviously have to include the information abut the meaning of N(t). This can be done simply by including it in params:

params:={Lambda1=0.029,b=0.5,phi1=0.25,phi2=1.01,mu=0.02,rho=0.1,delta=0.1,
f=0.85,theta=0.2,nu=0.33,h0=0.4,h1=0.08,h2=0.02,h3=0.06,h4=0.4,
  N(t)=S(t)+I1(t)+I2(t)+I3(t)+I4(t)+A(t)};

After that it works for me.


@Carl Love I believe you are wrong, see the example below. I remember reading about the change from rk4 to rkf45 some years ago and then thought the same as you are expressing.
However, I soon discovered that it does matter:

restart;
p1:=DEtools[DEplot](diff(x(t),t)=sin(x(t))+sin(t),x(t),t=0..100,[x(0)=0],linecolor=blue,arrows=none):
plots:-display(p1,size=[1000,200]);
p2:=DEtools[DEplot](diff(x(t),t)=sin(x(t))+sin(t),x(t),t=0..100,[x(0)=0],linecolor=blue,arrows=none,stepsize=0.1):
plots:-display(p2,size=[1000,200]);

Since the help page for DEplot doesn't mention the effect of stepsize even in the default case (rkf45) I shall suggest (via an SCR) that the help page be updated.

To see the limit cycle mentioned by me under the discussion using DEplot you don't need all these initial points.

Using one suffices. I chose one not too far away from the 3rd equilibrium point:

sol:=solve({eq1=0,eq2=0,eq3=0,eq4=0,eq5=0},{x,y,z,v,w});
pts:=map(subs,[sol],[x,y,z,v,w]);
eps:=.1:
ini:=[x,y,z,v,w](0)=~pts[3]+[eps$5];
res:=dsolve({Eq1,Eq2,Eq3,Eq4,Eq5} union {ini[]},numeric,maxfun=0);
plots:-odeplot(res,[x(t),y(t)],500..511);
XYZ:=plots:-odeplot(res,[x(t),y(t),z(t)],500..511):
YZV:=plots:-odeplot(res,[y(t),z(t),v(t)],500..511):
ZVW:=plots:-odeplot(res,[z(t),v(t),w(t)],500..511):
plots:-display(Array([XYZ,YZV,ZVW]));


@J4James I don't know what your objective is, but often people are interested in the long term behavior of the solutions (example: the Lorenz strange attractor).

If that is also your interest then you should use a time range like t=t1..t2, where t1 is somewhat large and t2-t1 is large enough to give an idea of the long term behavior. In case of a limit cycle that time difference should be just large enough to represent the cycle. In case of a more complicated long term behavior it is not so clear.

But start by trying  t = 250..260 or similar. While experimenting you might as well use stepsize=0.1.
Replace the default thickness with the one suggested by Carl.

There is graphical evidence of a limit cycle. To add more excitement I included z in the plot and used t=500..510.
Notice the need for increasing maxfun (actually I set it at infinity by maxfun=0):

DEtools[DEplot3d]([Eq1,Eq2,Eq3,Eq4,Eq5],[x(t),y(t),z(t),v(t),w(t)],t=500..510,initialset,stepsize=0.1,color=blue,linecolor=magenta,axes=boxed,scene=[x,y,z],x=5.2..7.2,y=0.2..1.6,z=0..0.15,obsrange=false,thickness=0,maxfun=0);


@J4James I now remember that there is an option ,obsrange=false.

Use that and keep your original range.

@Carl Love I think you are right. I tried splitting the initial set in two according to the following procedure Q.
Notice that the range for x has been widened to begin with 5.

Q:=proc(ini) local x1,y1,a,b,c,d;
    a:=5; b:=7.2; c:=0.2; d:=1.6;
    x1,y1:=op(subs(ini,[x(0),y(0)])); (x1-a)*(x1-b)<=0 and (y1-c)*(y1-d)<=0
end proc;
Q(initialset[166]); #Test

iniset1,iniset2:=selectremove(Q,initialset):
nops~([iniset1,iniset2]);

DEtools[DEplot]([Eq1,Eq2,Eq3,Eq4,Eq5],[x(t),y(t),z(t),v(t),w(t)],t=0..30,x=5..7.2,y=0.2..1.6,iniset1 ,stepsize=0.1,color=blue,linecolor=magenta,axes=boxed,scene=[x,y]);

DEtools[DEplot]([Eq1,Eq2,Eq3,Eq4,Eq5],[x(t),y(t),z(t),v(t),w(t)],t=0..30,x=5..7.2,y=0.2..1.6,iniset2 ,stepsize=0.1,color=blue,linecolor=magenta,axes=boxed,scene=[x,y]);




@J4James I tried the following, where I only took the last 11 of the initial conditions and only used time 0..30 (my patience is limited too). I removed restrictions on x and y and also the arrows option as it doesn't make much sense here (and is ignored anyway).

It worked fine.

DEtools[DEplot]([Eq1,Eq2,Eq3,Eq4,Eq5],[x(t),y(t),z(t),v(t),w(t)],t=0..30,initialset[170..180],stepsize=0.01,color=blue,linecolor=magenta,axes=boxed,scene=[x,y]);

First 126 127 128 129 130 131 132 Last Page 128 of 232