introduction to computational methods -...

122
Introduction to Computational Methods Maria Leite Benito Chen-Charpentier Folashade Agusto

Upload: dangduong

Post on 12-Dec-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Introduction to Computational Methods

Maria LeiteBenito Chen-Charpentier

Folashade Agusto

Page 2: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 3: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Introduction to Numerical Methods and Matlab Programming for Engineers

Todd Young and Martin J. Mohlenkamp

http://www.math.ohiou.edu/courses/math3600/book.pdf

Page 4: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

NUMERICAL METHODS IN ENGINEERING WITH

MATLAB

Jaan Kiusalaas

http://shoni2.princeton.edu/ftp/lyo/journals/Kiusalaas-NumMethodsEngineerMATLAB-CambUnivPress2005.pdf

Page 5: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 6: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Programming Languages

Fortran 90

C

C++

Fast (compiled) but require more programmer effort and knowledge

Page 7: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

High Level Languages

Matlab

Gnu Octave

Scilab

R

Python

Slower (interpreted) but easier to use.

Good for small to medium size numerical simulations.

Page 8: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Computer Algebra Systems

Maple

Mathematica

Maxima

Sage

Can do symbolic computations

Page 9: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 10: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 11: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 12: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Matlab

https://www.mathworks.com/

Widely available and used for numerical simulations.

Many methods and toolboxes.

Great support.

Relatively expensive.

Symbolic part lacks.

Page 13: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Scilab

http://www.scilab.org/

Free.

Many libraries

Good support

Interfaces with other languages.

Page 14: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 15: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Recommended software

Octave for numerical simulations and plotting

Maxima for symbolic calculations and plotting

Xppaut for bifurcation analysis

Page 16: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 17: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Symbolic package weak.

Many packages.

Page 18: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 19: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 20: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Octave GUI

Has a GUI with an editor

Page 21: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 22: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 23: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Command window

Page 24: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Editor window

Page 25: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 26: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 27: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 28: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 29: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 30: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 31: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 32: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 33: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 34: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 35: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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)

Page 36: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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);

Page 37: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 38: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 39: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 40: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 41: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 42: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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];

Page 43: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 44: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 45: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 46: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 47: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 48: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 49: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 50: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 51: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

wxmaxima

Page 52: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

wxmaxima

Page 53: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 54: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 55: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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);

Page 56: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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)*/

Page 57: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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 */

Page 58: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;"]);

Page 59: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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 */

Page 60: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 61: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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] */

Page 62: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 63: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 64: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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]);

Page 65: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 66: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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);

Page 67: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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))$

Page 68: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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) )$

Page 69: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

SIRS output

Page 70: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 71: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 72: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 73: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 74: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 75: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 76: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 77: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 78: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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]);

Page 79: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

Page 80: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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);

Page 81: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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]])$

Page 82: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Results

Page 83: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 84: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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;

….

Page 85: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Results

Page 86: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 87: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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]);

Page 88: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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);

Page 89: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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])$

Page 90: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Results

Page 91: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 92: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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);

…..

Page 93: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Results

Page 94: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 95: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 96: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 97: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 98: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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/

Page 99: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 100: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 101: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Homepage:

http://www.math.pitt.edu/~bard/xpp/xpp.html

Page 102: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Write your equations, parameters (values you may want to change), initial conditions and xpp and auto parameters in a file with suffix .ode

Example:

Page 103: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 104: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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.

Page 105: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

xpp GUI

Drag the .ode file and drop it on xpp.bat

Page 106: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 107: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 108: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 109: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 110: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 111: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 112: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 113: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 114: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 115: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 116: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 117: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 118: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

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

Page 119: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Lambda=.005

Page 120: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Lambda=.001

Page 121: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function
Page 122: Introduction to Computational Methods - ema2018.ucad.snema2018.ucad.sn/wp-content/uploads/2018/05/Introduction-to... · Using Octave Write two programs: rhs.m containing the function

Check for negative values: