Upload
dangduong
View
228
Download
0
Embed Size (px)
Citation preview
Introduction to Computational Methods
Maria LeiteBenito Chen-Charpentier
Folashade Agusto
Numerical Methods
Some references for numerical methods are:
Introduction to Numerical Methods
Lecture notes for MATH 3311
Jeffrey R. Chasnov
https://www.math.ust.hk/~machas/numerical-methods.pdf
Introduction to Numerical Methods and Matlab Programming for Engineers
Todd Young and Martin J. Mohlenkamp
http://www.math.ohiou.edu/courses/math3600/book.pdf
NUMERICAL METHODS IN ENGINEERING WITH
MATLAB
Jaan Kiusalaas
http://shoni2.princeton.edu/ftp/lyo/journals/Kiusalaas-NumMethodsEngineerMATLAB-CambUnivPress2005.pdf
Numerical Methods and Modeling for Chemical Engineers
Mark E. Davis
https://authors.library.caltech.edu/25061/1/NumMethChE84.pdf
Concentrates on ODE’s and PDE’s.
Programming Languages
Fortran 90
C
C++
Fast (compiled) but require more programmer effort and knowledge
High Level Languages
Matlab
Gnu Octave
Scilab
R
Python
Slower (interpreted) but easier to use.
Good for small to medium size numerical simulations.
Computer Algebra Systems
Maple
Mathematica
Maxima
Sage
Can do symbolic computations
Specialized software
xpp (or xppaut)
http://www.math.pitt.edu/~bard/xpp/xpp.html
Numerical solutions of differential equations plus bifurcation diagrams using AUTO. Easier to use than AUTO.
The web page includes a tutorial and examples.
AUTO-07p
AUTO is a software for continuation and bifurcation problems in ordinary differential equations.
https://sourceforge.net/projects/auto-07p/files/auto07p/
There is manual and examples at the home page:
http://indy.cs.concordia.ca/auto/
Harder to use than xppaut.
A good tutorial are the lecture notes:
NUMERICAL ANALYSIS of NONLINEAR EQUATIONS
Eusebius Doedel
http://indy.cs.concordia.ca/auto/notes.pdf
Software for optimal control
bocop is an open-source toolbox for solving optimal control problems
http://www.bocop.org/
Very powerful with great minimization software but the problem description has to be written in C++. But there are examples that can be modified.
Matlab
https://www.mathworks.com/
Widely available and used for numerical simulations.
Many methods and toolboxes.
Great support.
Relatively expensive.
Symbolic part lacks.
Scilab
http://www.scilab.org/
Free.
Many libraries
Good support
Interfaces with other languages.
Tutorial:
http://scilab.io/getting-started-content/
Good documentation
Not matlab compatible but the program will convert matlab to scilab and there is also a conversion table:
https://help.scilab.org/docs/5.5.2/en_US/section_36184e52ee88ad558380be4e92d3de21.html
Several books in English, French and other languages.
Recommended software
Octave for numerical simulations and plotting
Maxima for symbolic calculations and plotting
Xppaut for bifurcation analysis
Gnu Octave
https://www.gnu.org/software/octave/
Free
Very compatible with matlab.
Very good online documentation:
https://octave.org/doc/interpreter/
Tutorials:
http://www-mdp.eng.cam.ac.uk/web/CD/engapps/octave/octavetut.pdf
http://ais.informatik.uni-freiburg.de/teaching/ws11/robotics2/pdfs/rob2-03-octave.pdf
Symbolic package weak.
Many packages.
Programming for Computations
- A Gentle Introduction to Numerical Simulations with
MATLAB/Octave
Svein Linge and Hans Petter Langtangen
https://hplgit.github.io/prog4comp/doc/pub/p4c_Matlab.pdf
Numerical Methods Library for OCTAVE, Users Guide
Lilian Calvet
http://www.ipb.pt/~balsa/teaching/MA08_09/UsersGuide.pdf
A library of common numerical methods extending the ones in Octave
Octave GUI
Has a GUI with an editor
Even though octave includes an editor, an external editor like notepad++ that has syntax highlighting for matlab/octave and other languages:
https://notepad-plus-plus.org/
Octave has very good numerical routines and graphics.
Using Octave
Write two programs: rhs.m containing the function rhs that calculates the rhs of the equations and main.m with the main program, using either an editor or the octave GUI editor. Routines have to end with endfunction.
Use global to pass parameters.
Save them in the same folder. Open main.m from the editor in the GUI and run it using the tool bar.
Command window
Editor window
Some examples in octave
The following examples illustrate the use of octave in typical epidemiological and ecological problems.
The code is included
Results are shown
SIR model, main program
% SIR model with constant population. Recovered get immunity.
% Susceptibles, S(t)=x(1)
% Infectives, I(t)=x(2)
% Recovered, R(t)
% dS/dt=-a*S*I, dI/dt=a*S*I-b*I, dR/dt=b*I
% Use that the total population N=S+I+R to solve only first two equations
global a b;
a=.01;
b=.1;
%initial conditions
x0=[99;1];
%Total population
N=100;
continuation
% time interval
t0 = 0;
tf =60;
% plot the 2-d vector field with arrows.
figure(1)
clf;
[S,I] = meshgrid(0:10:100);
%xp=sirrhs(1,[S,I]);
Sq = -a*S.*I;
Iq = a*S.*I-b*I;
quiver(S,I,Sq,Iq,1);
print -depsc2 sir_fig1.eps;
continuation
[t x] = ode45('sirrhs',[t0 tf],x0);
%Calculate recovered
R= N-x(:,1)-x(:,2);
figure(2)
clf
plot(t,x(:,1),'b-','LineWidth',2,t,x(:,2),'r-','LineWidth',2,t,R,'g-','LineWidth',2);
ylabel('Population Size','fontsize',15);
xlabel('Time','fontsize',15);
legend('Susceptibles', 'Infectives', 'Recovered');
print -depsc2 sir_fig2.eps;
continuation
figure(3)
clf
quiver(S,I,Sq,Iq,1);
hold on;
plot(x(:,1),x(:,2),'b-','LineWidth',2);
ylabel('Infectives','fontsize',15);
xlabel('Susceptibles','fontsize',15);
%legend('Susceptibles', 'Infectives', 'Recovered');
hold off;
print -depsc2 sir_fig3.eps;
sirrhs.m, rhs of differential system
% the rhs of the SIR system. Saved as sirrhs.m
function xp = sirrhs(t,x)
global a b;
xp= zeros(2,1);
xp(1) = -a*x(1)*x(2) ;
xp(2) = a*x(1)*x(2)-b*x(2) ;
endfunction
Lotka-Volterra predator-prey model
In order to calculate fixed points, need to write the rhs as a function in a slightly different form
lotkafixed.m:
% the rhs of the Lotka-Volterra system. Saved as lotkafixed.m to calculate fixed points
function xp = lotkafixed(x)
global r b c m ;
xp= zeros(2,1);
xp(1) = r*x(1)-b*x(1)*x(2) ;
xp(2) = c*x(1)*x(2)-m*x(2) ;
endfunction
Lotka.m, main program
% dN/dt=r*N-c*N*P, dP/dt=b*N*P-m*P
global r b c m;
r=2.;
b=1;
c=.5;
m=.8;
%initial conditions
x0=[2;1];
%find fixed points
[fixed,fval, info]= fsolve ('lotkafixed', x0)
continuation
% time interval
t0 = 0;
tf =10;
% for vector field.
[N,P] = meshgrid(0:.5:4);
Nq = r*N-b*N.*P;
Pq = c*N.*P-m*P;
%Solve system of ODE's
opt = odeset ( "RelTol", 1e-6);
[t x] = ode45('lotkarhs',[t0 tf],x0,opt);
continuation
figure(1)
clf
plot(t,x(:,1),'b-','LineWidth',2,t,x(:,2),'r-','LineWidth',2);
ylabel('Population Size','fontsize',15);
xlabel('Time','fontsize',15);
legend('Prey', 'Predator');
print -depsc2 lotka_fig2.eps;
continuation
figure(2)
clf
quiver(N,P,Nq,Pq);;
hold on;
plot(x(:,1),x(:,2),'b-','LineWidth',2);
ylabel('Prey','fontsize',15);
xlabel('Predator','fontsize',15);
hold off;
print -depsc2 lotka_fig3.eps;
lotkarhs.m, rhs of ode system
% the rhs of the lotka-volterra system. Saved as lotkarhs.m
function xp = lotkarhs(t,x)
global r b c m ;
xp= zeros(2,1);
xp(1) = r*x(1)-b*x(1)*x(2) ;
xp(2) = c*x(1)*x(2)-m*x(2) ;
endfunction
Rosenzweig-MacArthur model for predator prey. Main program
% Rosenzweig-MacArthur model for predator prey
% Prey, N(t)=x(1)
% Predator, P(t)=x(2)
% dN/dt=r*N(1-n/K)-c*N*P/(h+N), dP/dt=b*N*P/(h+N)-m*P
%Predator prey with logistic growth for prey an Holling type interaction
global r b c m K h;
r=2.; b=1; c=.5; m=.8; K=6; h=1;
%with these new b and c two solutions
%b=2; c=1.5;
%initial conditions
x0=[2;1];
continuation
%find fixed points
[fixed,fval, info]= fsolve ('rosenzfixed', x0)
% time interval
t0 = 0;
tf =30;
% For vector field
[N,P] = meshgrid(0:.5:4);
Nq = r*N.*(1-N./K)-b*N.*P./(h.+N);
Pq = c*N.*P./(h.+N)-m*P;
continuation
%Solve system of ODE's
opt = odeset ( "RelTol", 1e-6);
[t x] = ode45('rosenzrhs',[t0 tf],x0,opt);
figure(1)
clf
plot(t,x(:,1),'b-','LineWidth',2,t,x(:,2),'r-','LineWidth',2);
ylabel('Population Size','fontsize',15);
xlabel('Time','fontsize',15);
legend('Prey', 'Predator');
print -depsc2 rosenz_fig2.eps;
continuation
figure(2)
clf
quiver(N,P,Nq,Pq);;
hold on;
plot(x(:,1),x(:,2),'b-','LineWidth',2);
ylabel('Prey','fontsize',15);
xlabel('Predator','fontsize',15);
hold off;
print -depsc2 rosenz_fig3.eps;
rosenzrhs.m, rhs of ode system
% the rhs of the Rosenzweig-MacArthur system. Saved as rosenzrhs.m
function xp = rosenzrhs(t,x)
global r b c m K h;
xp= zeros(2,1);
xp(1) = r*x(1)*(1-x(1)/K)-b*x(1)*x(2)/(h+x(1)) ;
xp(2) = c*x(1)*x(2)/(h+x(1))-m*x(2) ;
endfunction
rosenzfixed.m, for fixed points
% the rhs of the Rosenzweig-MacArthur system. Saved as rosenzfixed.m to calculate %fixed points
function xp = rosenzfixed(x)
global r b c m K h;
xp= zeros(2,1);
xp(1) = r*x(1)*(1-x(1)/K)-b*x(1)*x(2)/(h+x(1)) ;
xp(2) = c*x(1)*x(2)/(h+x(1))-m*x(2) ;
endfunction
Maxima
Symbolic and numerical calculations and plotting
Two main GUI’s:
Wxmaxima (more powerful)
Xmaxima.
Or command line
Wxmaxima has toolbar with the most common commands
https://htmlpreview.github.io/?https://github.com/andrejv/wxmaxima/blob/master/info/wxmaxima.html
wxmaxima
wxmaxima
Maxima
Good short introductions are:
Introduction to Maxima by Richard Rand
http://maxima.sourceforge.net/docs/manual/intromax.pdf
A micro introduction to Maxima at Harvard
http://www.math.harvard.edu/computing/maxima/
This one also has an equivalence table with Mathematica
And of course the manual:
http://maxima.sourceforge.net/docs/manual/maxima.pdf
Even though commands can be entered directly into wxmaxima, or using its toolbar, it is easier to write a batch file in an editor, save it with a name ending in .mac, example file.mac, and the clicking on the toolabar file > Batch file …> file.mac
Or copy and paste.
Brief Introduction to Maxima
Place cursor on input cell and type 1+1; shift+enter to evaluate
End command with ; or $ to suppress output
% is the previous output or use %o1, %o2, etc.
Maxima tries to keep calculations precise so it doesn’t evaluate
sqrt(2*%pi); use float(%); to evaluate it.
To assign a name to a variable: var_name: value;
Define a function and integrate it:
f(x):= x^3$
Integrate(f(y),y);
continuation
To make sure integral is well defined:
assume(a>0)$
Integrate(1/(x+a),x,0,1);
forget(a>0);
Some commands:
solve(a*x^2+b*x+c=0,x);
A: matrix([1,0], [%e. %pi]);
B: invert(A);
C: A.B; /* . Is the matrix product (this is a comment in maxima)*/
eigenvalues(A);
Differentiation: use diff or ‘diff unevaluated derivative:
f(x):= exp(x)$
diff(f(x),x);
g(y):= log(y)+y^2$
diff (g(f(x)), x);
Exact solution of ODE’s:
soln: ode(‘diff(x,t,2) + 4*x=0, x,t); /*second order */
ic2(soln, t=0, x=1, ‘diff(x,t)=0); /*initial conditions */
plotting
wxplot2d([sin(x)], [x-%pi,%pi])$
More options, ex: [lines, linewidth, line color]
wxplot2d([f(x),g(x)], [x, -2, 10], [xlabel, “x”], [ylabel, “y”], [legend, “f”, “g”], [style, [lines, 1,1], [lines 2,4]]);
Solve one ODE and plot it:
sol:rk([-x],x,2.,[t,0,1,0.1])$
wxplot2d([discrete,sol],[style,lines],[y,0,2],
[gnuplot_preamble, "set grid;"]);
System of 2 ODE’s:
sol:rk([rhs1,rhs2],[x,y],[1,0],[t,0,5,0.1])$
sol1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$
sol2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$
wxplot2d([[discrete,sol1],[discrete,sol2]],
[style,[points,1]],[y,0,2]);
Or use rkf45 /* load(rkf45 */
Other useful commands
kill(a); /* remove value of a*/
kill(all); /*remove all assigned values */
expr, numer; /* convert to floating point */
expr, t=0, numer; /* replace t by 0 in expr */
expr, ratsimp; /* simplify expr */
expr, ratsimp, numer;
Discrete systems
Solve y[n+1]=F(y[[n]):
y[0]: 1$
y[n] := F(y[n-1])$
y[10];
load(dynamics)$ /* for graphing*/
evolution(F(y), y0, max_n)$ /* plots y[n] vs n */
staircase(F(y),y0,max_n)$ /* plots y[n+1] vs y[n] */
Some examples using maxima
The following examples illustrate using maxima to find fixed points and corresponding eigenvalues symbolically, evaluating them for given values, doing numerical simulations and plotting results.
SIRS model
Maxima will find the fixed points and the eigenvalues of the linearized problem at the fixed points symbolically for general values of the parameters. Sometimes numerical values have to be given. Even though it can symbolically solve ODE’s, our systems require numerical solution.
It will plot trajectories, phase planes, etc.
sirs.mac, maxima batch file
remvalue(all);
load(drawdf)$
load(draw)$
load(rkf45)$
/* Define the rhs */
eq1:-b*S*I+c*(N-S-I);
eq2:b*S*I-e*I;
fixed:solve([eq1,eq2],[S,I]);
J: jacobian([eq1,eq2],[S,I]);
J1: ev(J,fixed[1]);
J2: ev(J,fixed[2]);
continuation
/* first list eigenvalues, second list multiplicities */
eigenvalues(J1);
eigenvalues(J2);
/* alternative way */
J11:subst(fixed[1],J);
eigenvalues(J11);
/* give values to parameters */
b:.01;
c:.05;
e:.1;
N:100;
continuation
nfixed:ev(fixed);
neq1:ev(eq1);
neq2:ev(eq2);
Jn: jacobian([neq1,neq2],[S,I]);
J1n: ev(Jn,fixed[1]);
J2n: ev(Jn,fixed[2]);
eigenvalues(J1n);
eigenvalues(J2n);
continuation
/* draw phase portrait with some trajectories */
wxdrawdf([neq1,neq2],[S,I],[S,0,100],[I,0,100], duration=40, solns_at([90,10], [70,20], [50,40], [10,80]))$
/* Do time integration */
soln1: rkf45([neq1,neq2],[S,I], [90,10], [t,0,50])$
/* output is a list of a list with entries t, S, I */
soln11: makelist([first(soln1[i]),second(soln1[i])], i,1,length(soln1))$
soln12: makelist([first(soln1[i]),third(soln1[i])], i,1,length(soln1))$
/* calculate R recovered */
soln13: makelist([first(soln1[i]), N-second(soln1[i])-third(soln1[i])],i,1,length(soln1))$
continuation
/* plot solution */
wxdraw2d(points_joined = true,yrange=[0,100],line_width = 2,color = red,points(soln11) )$
wxdraw2d(points_joined = true,yrange=[0,100],line_width = 2,color = blue,points(soln12) )$
wxdraw2d (points_joined = true,yrange=[0,100],line_width = 2,color = green,points(soln13) )$
wxdraw2d (points_joined = true,yrange=[0,100],line_width = 2,point_size=0,color = red, points(soln11), color=blue, points(soln12), color = green,points(soln13) )$
SIRS output
Lotka_Volterra predator-prey model
/* Lotka-Volterra N is the prey and P the predator*/
/* used rk and plot2d */
kill(all);
load(drawdf)$
/*load(draw)$
load(rkf45)$*/
/* Define the rhs */
eq1:r*N-c*N*P;
eq2:b*N*P-m*P;
fixed:solve([eq1,eq2],[N,P]);
continuation
J: jacobian([eq1,eq2],[N,P]);
J1: ev(J,fixed[1]);
J2: ev(J,fixed[2]);
/* first list eigenvalues, second list multiplicities */
eigenvalues(J1);
eigenvalues(J2);
/* give values to parameters */
r:2.;
b:.2;
c:.5;
m:.8;
continuation
nfixed:ev(fixed);
neq1:ev(eq1);
neq2:ev(eq2);
Jn: jacobian([neq1,neq2],[N,P]);
J1n: ev(Jn,fixed[1]);
J2n: ev(Jn,fixed[2]);
eigenvalues(J1n);
eigenvalues(J2n);
continuation
/* draw phase portrait with some trajectories */
wxdrawdf([neq1,neq2],[N,P],[N,0,20],[P,0,15], duration=40, solns_at([9,1], [7,2], [5,4], [1,8]))$
/* Do time integration */
soln1: rk([neq1,neq2],[N,P], [2,1], [t,0,50, .1])$
/* output is a list of a list with entries t, S, I */
soln11: makelist([first(soln1[i]),second(soln1[i])], i,1,length(soln1))$
soln12: makelist([first(soln1[i]),third(soln1[i])], i,1,length(soln1))$
/* plot solution */
wxplot2d([[discrete, soln11],[discrete,soln12]], [style, [lines,2]])$
Results
Rosenzweig-MacArthur Predator-prey, only functions definition
/* Rosenzweig-MacArthur N is the prey and P the predator*/
/* used rkf45 and draw2d */
kill(all);
load(drawdf)$
load(draw)$
load(rkf45)$
/* Define the rhs */
eq1:r*N*(1-N/K)-c*N*P/(h+N);
eq2:b*N*P/(h+N)-m*P;
….
Results
Bifurcation center to saddle
/* dx/dty=x+mu*y, dy/dt=x-y */
/*Use plotdf that includes sliders but plots only one trajectory */
/* at mu=-1 center to saddle */
kill(all);
load(plotdf)$
eq1:x+mu*y;
eq2:x-y;
fixed:solve([eq1,eq2],[x,y]);
J:jacobian([eq1,eq2],[x,y]);
continuation
fixed1: ev(fixed[1], mu=0);
J1: ev(J, fixed1, mu=0);
eigenvalues(J1);
/* mu <-1 */
fixed11: ev(fixed[1], mu=-2);
J11: ev(J, fixed11, mu=-2);
eigenvalues(J11);
continuation
plotdf([eq1,eq2], [x,y],
[parameters,"mu=1."],
[trajectory_at,1,2],[tstep,0.001],
[x,-10,10], [y,-10,10], [direction,forward],
[nsteps,300], [sliders,"mu=-5:5"], [versus_t,1])$
Results
SIR bifurcation, only function definition
/* Zhang Bif analysis of SIR */
/*Use plotdf that includes sliders but plots only one trajectory */
/* use lambda as the parameter. Do NOT assign valu until plodf*/
kill(all);
load(plotdf)$
A:15;d:.1;eps:.01;mu:.1;r:.8;alpha:.1; k:.1; /*endemic stable*/
d1:d+eps+mu;
eq1:A-d*S-lambda*S*I/(1+k*I);
eq2:lambda*S*I/(1+k*I)-d1*I-r*I/(1+alpha*I);
…..
Results
Notebooks in Maxima
From inside wxmaxima you can write a notebook that includes text and maxima commands.
The text can be edited and the commands can be executed or modified.
Commands executed out of order may give unexpected results.
Always clear memory before loading a notebook.
The saved notebook can include the output or not.
Maxima notes
Maxima has many packages including contrib_ode, lapack, minpack.
Octave is better numerically.
The Euler math tool box
http://euler.rene-grothmann.de/
is a math program combining numerical and symbolic tools using Maxima in one free package. It is quite similar to Matlab, but not compatible.
sage or sagemath is a free mathematics software system. It builds on top of many existing open-source packages: NumPy, SciPy, matplotlib, Sympy, Maxima, GAP, FLINT, Rand many more.
Very powerful with commands in python like syntax.
It can be run on the cloud using Cocalc
https://cocalc.com/?utm_source=sagemath.org&utm_medium=landingpage
or SageMathCell
http://sagecell.sagemath.org/
xpp or xppaut
Solves numerically ordinary differential equations, delay equations, difference equations, functional equations and stochastic equations. Includes auto for bifurcation analysis.
Also plots.
Comes with a GUI.
Book: Simulating, Analyzing, and Animating Dynamical Systems: A Guide to Xppaut for Researchers and Students (Software, Environments, Tools) (Software, Environments and Tools) 1st Edition
by Bard Ermentrout , SIAM
Write your equations, parameters (values you may want to change), initial conditions and xpp and auto parameters in a file with suffix .ode
Example:
Simple bifurcation example
# Simple bifurcation du/dx=mu x-x^3; dy/dt=-y
par mu=1
x'=mu*x-x^3
y'=-y
x(0)=1
y(0)=0
@ xp=x,yp=y,xlo=-.25,xhi=1.25,ylo=-.5,yhi=1,total=100
@ maxstor=10000
done
xpp notes
The lines starting with @ change default values of xpp and auto parameters. xp and yp are the functions to be plotted in the x and y axes. Total is the total integration time. Maxstor is the maximum number of stored values during the numerical integration.
Lines starting with # are comments
The file ends with done
Inside xpp you can change the values of the parameters, equations, initial conditions and more.
xpp GUI
Drag the .ode file and drop it on xpp.bat
Equilibrium points and their stability
Click on Sing pts -> Go to get an equilibrium point.
It may be necessary to repeat click on mouse or montecar to get others.
The cmd.exe windows gives the values of the eigenvalues:
-2.003 + i 0.000
-1.000 + i 0.000
Direction field
Click on Viewaxes to choose y vs x and ranges
Click on Dir.field/flow ->Direct field
On upper left corner give Grid and return
If desired click on nullclines and on Initialconds ->Mice to choose some trajectories
Auto
Auto needs a steady solution (or a periodic solution) as a starting point. In xpp click Initialcons->Go and the I L several times until solution doesn’t change.
Click File->auto
Check Parameter for the continuation parameter and Numerics. Ds>0 increases the parameter while Ds<0 decreases it. Then Run->steadystates to compute the branch
Auto marks special points:
EP Endpoint of a branch
LP Limit point or turning point of a branch
TR Torus bifurcation from a periodic
PD Period doubling bifurcation
UZ User defined function
MX Failure to converge
BP Bifurcation or branch point
HB Hopf bifurcation
To continue from a special point Grab, choose point by using arrows and enter. Maybe change parameters (Ds?) and run again. For a Hopf bifurcation Run->periodic
To save a diagram use File->postscript
Esc exits from a command.
Also look at cmd.exe window
Problem with limit point
# Simple bifurcation du/dx=mu-x^2; dy/dt=-y
par mu=1
x'=mu-x^2
y'=-y
x(0)=1
y(0)=0
@ xp=x,yp=y,xlo=-.25,xhi=1.25,ylo=-.5,yhi=1,total=100
@ maxstor=10000
done
An epidemic model
# Backward bifurcation of an epidemic model with saturated treatment
# function, Xu Zhang , Xianning Liu
# give parameters
param lambda=.01, d=.1, eps=.01, mu=.1, r=.8; alpha=.1, k=.1
# derived variables
!d1=(d+eps+mu)
#!A=d*(d+ eps+mu+r)/lambda
A=15
Continuation
#define ode's
S'=A-d*S-lambda*S*I/(1+k*I)
I'=lambda*S*I/(1+k*I)-d1*I-r*I/(1+alpha*I)
#Initial conditions
S(0)=30
I(0)=10
S'=A-d*S-lambda*S*I/(1+k*I)
I'=lambda*S*I/(1+k*I)-d1*I-r*I/(1+alpha*I)
#Initial conditions
S(0)=30
I(0)=10
Continuation
#Some xpp parameters
@total=200,dt=.1,xhi=160,ylo=0.,yhi=20.,bound=500,maxstor=100000,nplot=1,xp=S,yp=I
@ toler=.00001,meth=gear
@ ntst=30,dsmin=1e-4,dsmax=0.02,ds=.001,parmin=.01,parmax=1.5,autoxmin=0.0
@ autoxmax=40,autoymin=0,autoymax=20
@ nmax=10000
@ npr=1000
@ EPSU=.0001,EPSS=.0001,EPSL=.0001
done
Lambda=.005
Lambda=.001
Check for negative values: