Dynamical Systems with Applications using MATLAB 2nd Edition pdf pdf

  Stephen Lynch

Dynamical Systems with Applications using

MATLAB®

  Stephen Lynch Department of Computing and Mathematics, Manchester Metropolitan University School of Computing, Mathematics & Digital Technology, Manchester, UK

  ISBN 978-3-319-06819-0 e-ISBN 978-3-319-06820-6 DOI 10.1007/978-3-319-06820-6 Springer Cham Heidelberg New York Dordrecht London Library of Congress Control Number: 2014941703 Mathematics Subject Classification (2010): 37-01, 49K15, 78A60, 28A80, 80A30, 34H10, 34K18,

  70K05, 34C07, 34D06, 92B20, 94C05 © Springer International Publishing Switzerland 2014 This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

  Printed on acid-free paper Springer is part of Springer Science+Business Media (www.birkhauser-science.com)

  Preface ® ; 

  Since the first printing of this book in 2004, MATLAB has evolved from MATLAB version 6 to MATLAB version R2014b, where presently, the package is updated twice a year. Accordingly, the second edition has been thoroughly updated and new material has been added. In this edition, there are many more applications, examples, and exercises, all with solutions, and new sections on series solutions of ordinary differential equations, perturbation methods, normal forms, Gröbner bases, and chaos synchronization have been added. There are also new chapters on image processing and binary oscillator computing.

  This book provides an introduction to the theory of dynamical systems with the aid of MATLAB,

TM TM TM

  the Symbolic Math Toolbox , the Image Processing Toolbox , and Simulink . It is written for both senior undergraduates and graduate students. Chapter

  ovides a tutorial introduction to

  MATLAB—new users should go through this chapter carefully whilst those moderately familiar and

  

  • experienced users will find this chapter a useful source of reference. Chapters

  als with

  discrete systems, Chaps

  re devoted to the study of continuous systems using ordinary

  differential equations and Chaps. 

  

  lists three MATLAB-based examinations to be sat in a computer laboratory with access to MATLAB and Chap. 

  ists answers to all of the exercises given in the book. It should be pointed out that

  dynamical systems theory is not limited to these topics but also encompasses partial differential equations, integral and integro-differential equations, stochastic systems, and time-delay systems, for instance. References [1–5] given at the end of the Preface provide more information for the interested reader. The author has gone for breadth of coverage rather than fine detail and theorems with proofs are kept at a minimum. The material is not clouded by functional analytic and group theoretical definitions and so is intelligible to readers with a general mathematical background. Some of the topics covered are scarcely covered elsewhere. Most of the material in Chaps. 7, 10, 11, 15–19, and 21 is at postgraduate level and has been influenced by the author’s own research interests. There is more theory in these chapters than in the rest of the book since it is not easily accessed anywhere else. It has been found that these chapters are especially useful as reference material for senior undergraduate project work. The theory in other chapters of the book is dealt with more comprehensively in other texts, some of which may be found in the references section of the corresponding chapter. The book has a very hands-on approach and takes the reader from the basic theory right through to recently published research material.

  MATLAB is extremely popular with a wide range of researchers from all sorts of disciplines, it has a very user-friendly interface and has extensive visualization and numerical computation capabilities. It is an ideal package to adopt for the study of nonlinear dynamical systems; the numerical algorithms work very quickly, and complex pictures can be plotted within seconds. The Simulink accessory to MATLAB is used for simulating dynamical processes. It is as close as one can get to building apparatus and investigating the output for a given input without the need for an actual physical model. For this reason, Simulink is very popular in the field of engineering. Note that the latest student version of MATLAB comes with a generous additional ten toolboxes including the Symbolic Math Toolbox, the Image Processing Toolbox, and Simulink.

  The first chapter provides an efficient tutorial introduction to MATLAB. New users will find the tutorials will enable them to become familiar with MATLAB within a few hours. Both engineering well with one staff member to about twenty students in a computer laboratory. In most cases, I have chosen to list the MATLAB program files at the end of each chapter, this avoids unnecessary cluttering in the text. The MATLAB programs have been kept as simple as possible and should run under later versions of the package. The MATLAB program files and Simulink model files (including

  

xt, and

  then it is not too difficult to change parameters or equations to investigate other systems. Readers may be interested to hear that the MATLAB and Simulink model files have been downloaded over 30,000 times since they were uploaded in 2002 and that these files were selected as the MATLAB Central Pick of the Week in July 2013.

  

  • Chapters

   starts with a general introduction

  to iteration and linear recurrence (or difference) equations. The bulk of the chapter is concerned with the Leslie model used to investigate the population of a single species split into different age classes. Harvesting and culling policies are then investigated and optimal solutions are sought. Nonlinear discrete dynamical systems are dealt with in Chap. 

   . Bifurcation diagrams, chaos, intermittency,

  Lyapunov exponents, periodicity, quasiperiodicity, and universality are some of the topics introduced. The theory is then applied to real-world problems from a broad range of disciplines including population dynamics, biology, economics, nonlinear optics, and neural networks. Chapter

   is concerned with complex iterative maps; Julia sets and the now-famous Mandelbrot set are plotted.

  Basins of attraction are investigated for these complex systems. As a simple introduction to optics, electromagnetic waves and Maxwell’s equations are studied at the beginning of Cha

  omplex iterative equations are used to model the propagation of light waves through nonlinear optical fibers.

  A brief history of nonlinear bistable optical resonators is discussed and the simple fiber ring resonator is analyzed in particular. Chapter

  s devoted to the study of these optical resonators and

  phenomena such as bistability, chaotic attractors, feedback, hysteresis, instability, linear stability analysis, multistability, nonlinearity, and steady states are discussed. The first and second iterative methods are defined in this chapter. Some simple fractals may be constructed using pencil and paper in Cha

  

nd the concept of fractal dimension is introduced. Fractals may be thought of as

  identical motifs repeated on ever-reduced scales. Unfortunately, most of the fractals appearing in nature are not homogeneous but are more heterogeneous, hence the need for the multifractal theory given later in the chapter. It has been found that the distribution of stars and galaxies in our universe is multifractal, and there is even evidence of multifractals in rainfall, stock markets, and heartbeat rhythms. Applications in materials science, geoscience, and image processing are briefly discussed.

  TM

  Chapter

  ovides a brief introduction to the Image Processing Toolbox which is being used

  more and more by a diverse range of scientific disciplines, especially medical imaging. The fast Fourier transform is introduced and has a wide range of applications throughout the realms of science.

  

  • Chapters

   cover some theory of

  ordinary differential equations and applications to models in the real world are given. The theory of differential equations applied to chemical kinetics and electric circuits is introduced in some detail. The memristor is introduced and one of the most remarkable stories in the history of mathematics is relayed. Chapter

   ends with the existence and uniqueness theorem for the solutions of certain types

  of differential equations. A variety of numerical procedures are available in MATLAB when solving stiff and nonstiff systems when an analytic solution does not exist or is extremely difficult to find. The

  Cha

  

pplications are taken from chemical kinetics, economics, electronics, epidemiology,

  mechanics, and population dynamics. The modeling of the populations of interacting species is discussed in some detail in Chap. 

  nd domains of stability are discussed for the first time. Limit

  cycles, or isolated periodic solutions, are introduced in Chap. 

  ince we live in a periodic

  world, these are the most common type of solution found when modeling nonlinear dynamical systems. They appear extensively when modeling both the technological and natural sciences. Hamiltonian, or conservative, systems and stability are discussed in Chaps. 12, and 13 is concerned with how planar systems vary depending upon a parameter. Bifurcation, bistability, multistability, and normal forms are discussed.

  The reader is first introduced to the concept of chaos in continuous systems in Chaps. 

   ,

  where three-dimensional systems and Poincaré maps are investigated. These higher-dimensional systems can exhibit strange attractors and chaotic dynamics. One can rotate the three-dimensional objects in MATLAB and plot time series plots to get a better understanding of the dynamics involved. Once again, the theory can be applied to chemical kinetics (including stiff systems), electric circuits, and epidemiology; a simplified model for the weather is also briefly discussed. Chapter

   deals

  with Poincaré first return maps that can be used to untangle complicated interlacing trajectories in higher-dimensional spaces. A periodically driven nonlinear pendulum is also investigated by means of a nonautonomous differential equation. Both local and global bifurcations are investigated in Cha

   . The main results and statement of the famous second part of David Hilbert’s sixteenth

  problem are listed in Chap. 

  n order to understand these results, Poincaré compactification is

  introduced. The study of continuous systems ends with one of the author’s specialities—limit cycles of Liénard systems. There is some detail on Liénard systems, in particular, in this part of the book, but they do have a ubiquity for systems in the plane.

  A brief introduction to the enticing field of neural networks is presented in Chap. 

  magine

  trying to make a computer mimic the human brain. One could ask the question: In the future will it be possible for computers to think and even be conscious? The human brain will always be more powerful than traditional, sequential, logic-based digital computers and scientists are trying to incorporate some features of the brain into modern computing. Neural networks perform through learning and no underlying equations are required. Mathematicians and computer scientists are attempting to mimic the way neurons work together via synapses; indeed, a neural network can be thought of as a crude multidimensional model of the human brain. The expectations are high for future applications in a broad range of disciplines. Neural networks are already being used in machine learning and pattern recognition (computer vision, credit card fraud, prediction and forecasting, disease recognition, facial and speech recognition), the consumer home entertainment market, psychological profiling, predicting wave over-topping events, and control problems, for example. They also provide a parallel architecture allowing for very fast computational and response times. In recent years, the disciplines of neural networks and nonlinear dynamics have increasingly coalesced and a new branch of science called neurodynamics is emerging. Lyapunov functions can be used to determine the stability of certain types of neural network. There is also evidence of chaos, feedback, nonlinearity, periodicity, and chaos synchronization in the brain.

  Chapter s devoted to the new and exciting theory behind chaos control and synchronization. For most systems, the maxim used by engineers in the past has been “stability good, chaos bad,” but more and more nowadays this is being replaced with “stability good, chaos better.” There are exciting and novel applications in cardiology, communications, engineering, laser technology, and

  Chapter

  

ocuses on binary oscillator computing, the subject of UK, International and

  Taiwanese patents. The author and his coinventor, Jon Borresen, came up with the idea when modeling connected biological neurons. Binary oscillator technology can be applied to the design of arithmetic logic units (ALUs), memory, and other basic computing components. It has the potential to provide revolutionary computational speedup, energy saving, and novel applications and may be applicable to a variety of technological paradigms including biological neurons, complementary metal–oxide–semiconductor (CMOS), memristors, optical oscillators, and superconducting materials. The research has the potential for MMU and industrial partners to develop super fast, low-power computers and may provide an assay for neuronal degradation for brain malfunctions such as Alzheimer’s, epilepsy, and Parkinson’s disease!

  Examples of Simulink models, referred to in earlier chapters of the book, are presented in Chap. 

  

t is possible to change the type of input into the system, or parameter values, and investigate the

  output very quickly. This is as close as one can get to experimentation without the need for expensive equipment.

  Three examination-type papers are listed in Chap. 

  nd a complete set of solutions is listed in

  Cha .

  Both textbooks and research papers are presented in the list of references. The textbooks can be used to gain more background material, and the research papers have been given to encourage further reading and independent study.

  This book is informed by the research interests of the author which are currently nonlinear ordinary differential equations, nonlinear optics, multifractals, neural networks, and binary oscillator computing. Some references include recently published research articles by the author along with an international patent.

  The prerequisites for studying dynamical systems using this book are undergraduate courses in linear algebra, real and complex analysis, calculus, and ordinary differential equations; a knowledge of a computer language such as C or Fortran would be beneficial but not essential.

  Recommended Textbooks 1. M.P. Coleman, An Introduction to Partial Differential Equations with MATLAB , 2nd edn.

  Chapman and Hall/CRC Applied Mathematics and Nonlinear Science (Chapman and Hall/CRC, New York, 2013)

  2. B. Bhattacharya, M. Majumdar, Random Dynamical Systems: Theory and Applications (Cambridge University Press, Cambridge, 2007)

  3. R. Sipahi, T. Vyhlídal, S. Niculescu, P. Pepe (eds.), Time Delay Systems: Methods,

  Applications and New Trends . Lecture Notes in Control and Information Sciences (Springer, New

  York, 2012)

  4. V. Volterra, Theory of Functionals and of Integral and Integro-Differential Equations (Dover Publications, New York, 2005)

  5. J. Mallet-Paret, J. Wu, H. Zhu, Y. Yi, Infinite Dimensional Dynamical Systems (Fields

  Institute Communications) (Springer, New York, 2013) TM

  Instructors may be interested in two new features in MATLAB, namely, Cody Coursework and MATLAB apps. Instructors can automate grading of MATLAB coursework assignments using Cody Coursework; this is a free resource available to use for faculty who have an active site licence. toolboxes come with apps. More details can be found on the relevant MathWorks web pages.

  I would like to express my sincere thanks to MathWorks for supplying me with the latest versions of MATLAB and its toolboxes. Thanks also go to all of the reviewers from the editions of the Maple and Mathematica books. Special thanks go to Birkhäuser and Springer publishers. Finally, thanks to my family, especially my wife, Gaynor, and our children, Sebastian and Thalia, for their continuing love, inspiration, and support.

  Stephen Lynch Manchester, UK

  Contents

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

Index

  © Springer International Publishing Switzerland 2014 Stephen Lynch, Dynamical Systems with Applications using MATLAB®, DOI 10.1007/978-3-319-06820-6_1

  1. A Tutorial Introduction to MATLAB 1 Stephen Lynch

  (1) Department of Computing and Mathematics, Manchester Metropolitan University School of Computing, Mathematics & Digital Technology, Manchester, UK

  Aims and Objectives

  To provide a tutorial guide to MATLAB To give practical experience in using the package To promote self-help using the online help facilities To provide a concise source of reference for experienced users

  On completion of this chapter the reader should be able to use MATLAB and the Symbolic Math Toolbox; produce simple MATLAB programs; access some MATLAB commands and programs over the World Wide Web. It is assumed that the reader is familiar with either the Windows or UNIX platform. This book was prepared using MATLAB R2014b, but most programs should work under earlier and later versions of the package.

  The commands and programs listed have been chosen to allow the reader to become familiar with MATLAB and the Symbolic Math Toolbox within a few hours. They provide a concise summary of the type of commands that will be used throughout this book. New users should be able to start on their own problems after completing this tutorial, and experienced users should find this chapter an excellent source of reference. Of course, there are many MATLAB textbooks on the market for those who require further applications or more detail. Note that from version 5, the Symbolic Math Toolbox is powered by the MuPAD symbolic engine, and nearly all Symbolic Math Toolbox functions work the same way as in previous versions. The Symbolic Math Toolbox provides tools for solving and manipulating symbolic math expressions and performing variable-precision arithmetic. The toolbox contains hundreds of MATLAB symbolic functions that leverage the MuPAD engine for tasks such as differentiation, integration, simplification, transforms, and equation solving. See the online MATLAB Help pages if you require further information.

  If you experience any problems, there are several options for you to take. There is an excellent

  

  • – index within MATLAB, there are thousands of textbooks, see references [

  , for example, and

  MATLAB program files (or M-files) can be downloaded from the MATLAB Central File Exchange at the link

  Download the zipped M-files and extract the relevant M-files from the archive onto your computer. Since 2002, the author’s files associated with the first edition of this book have been downloaded over 30,000 times by users from all over the world.

  To start MATLAB, simply double-click on the MATLAB icon. In the UNIX environment, one types MATLAB as a shell command. The author has used the Windows platform in the preparation of this material. When MATLAB starts up, by default three windows are displayed entitled Current Folder, Command Window, and Workspace. Figure

   shows a typical screen when running

  MATLAB. Each of the windows appearing in Fig. 

  ill now be described: Fig. 1.1 The MATLAB user interface

Current Folder. This window shows the current folder where files are listed. Note that when typing

pwd in the Command Window, the command also displays the MATLAB current folder.

  Command Window. This is where the user types in MATLAB commands followed by the

  RETURN or ENTER key on the keyboard. If you do not want to see the result (e.g., you would not want to see a list of numbers from 1 to 1,000), then use the semicolon delimiter.

  Workspace. The workspace consists of the set of variables built up during a session of using the MATLAB software and stored in memory.

  The Command Window is where the MATLAB commands are typed and executed, and this is where the user can use MATLAB just like a graphing calculator. When in the Command Window, command lines may be returned to and edited using the up and down arrow keys. If you do make a typing error, MATLAB will give an error: message and even point to the mistake in the code. Do not re-type the line, simply use the up arrow key and edit your mistake. To clear the Command Window simply type >> clc after the command prompt.

  By clicking on New Script in the top left corner of the MATLAB user interface (see Fig

   ) a

  new program file can be typed in the MATLAB editor. In this chapter, each MATLAB program is displayed between horizontal lines and kept short to aid in understanding; the output is also included. Take care, the MATLAB files (also known as M-files or script files ) will only run if they are in the

  1.

  Array indices start with 1 and not 0. In some programs a translation may be required to start indices with zero.

  Using the correct numerical solver for your particular problem.

  The reader should also be aware that even when the programs run successfully the output may not be correct. The following phenomena can greatly affect the results obtained for nonlinear dynamical systems: Chaos and sensitivity to initial conditions.

  Without the Symbolic Math Toolbox, MATLAB gives approximate answers.

  In MATLAB it is better (though not easier) to use matrix or vector operations instead of loops in programs.

  Some functions such as max, min, sort, sum, mean, etc., behave differently for complex and real data.

  Take care with element-wise and matrix-matrix multiplication.

  MATLAB allows use of variable names of pre-defined functions. For example, you can set rand = 1 which means that you cannot subsequently use the rand command. Readers should use the which command to check variable names.

  Some Well-Known Pitfalls of MATLAB

  2.

  3. results obtained with MATLAB should be verified by experiment where possible.

  2.

  1.

  6.

  5.

  4.

  3.

  Feedback, especially in the case of the second iterative method which is defined later in this book.

1.1 Tutorial One: The Basics and the Symbolic Math Toolbox (1 h)

  There is no need to copy the comments, they are there to help you. Click on the MATLAB icon and copy the command after the >> prompt. Press Return at the end of a line to see the answer or use a semicolon to suppress the output. You can interrupt a computation at any time by holding Ctrl+C. This tutorial should be run in the Command Window .

  MATLAB commands Comments >> % This is a comment. % Helps when writing % programs.

  >> 3^2*4-3*2^5*(4-2) % Simple arithmetic. >> sqrt(16) % The square root. >> % Vectors and Matrices. >> u=1:2:9 % A vector u=(1,3,5,7,9). >> v=u.^2 % A vector v=(1,9,25,49,81). >> A=[1,2;3,4] % A is a 2 by 2 matrix. >> A’ % The transpose of matrix A. >> det(A) % The determinant of a matrix. >> B=[0,3,1;0.3,0,0;0,0.5,0] % B is a 3 by 3 matrix. >> eig(B) % The eigenvalues of B. >> % List the eigenvectors and eigenvalues of B. >> [Vects,Vals]=eig(B) >> C=[100;200;300]

  % A 3 by 1 matrix. >> D=B*C % Matrix multiplication. >> E=B^4 % Powers of a matrix. >> % Complex numbers. >> % The semicolons suppress the output. >> z1=1+i;z2=1-i;z3=2+i; >> z4=2*z1-z2*z3

  % Simple arithmetic. >> abs(z1) % The modulus. >> real(z1) % The real part. >> imag(z1) % The imaginary part. >> exp(i*z1) % Returns a complex number. >> % The Symbolic Math Toolbox. >> sym(1/2)+sym(3/4) % Symbolic evaluation. >> % Double precision floating point arithmetic. >> 1/2+3/4 >> % Variable precision arithmetic (50 sig figs).

  >> vpa(pi,50) >> syms x y z % Symbolic objects. >> z=x^3-y^3 >> factor(z)

  % Factorization. >> % Symbolic expansion of the last answer. >> expand(ans) >> simplify(z/(x-y)) % Symbolic simplification.

  >> % Symbolic solution of algebraic equations. >> [x,y]=solve(’x^2-x’,’2*x*y-y^2’) >> syms x mu

  >> fof=subs(f,x,f) % A function of a function.

  >> limit(x/sin(x),x,0) % Limits. >> diff(f,x) % Differentiation. >> % Partial differentiation, (with respect to y twice). >> syms x y >> diff(x^2+3*x*y-2*y^2,y,2) >> int(sin(x)*cos(x),x,0,pi/2) % Integration. >> int(1/x,x,0,inf) % Improper integration. >> syms n s w x >> s1=symsum(1/n^2,1,inf) % Symbolic summation.

  >> g=exp(x) >> taylor(g,’Order’,10) % Taylor series expansion. >> syms x s >> laplace(x^3)

  % Laplace transform. >> ilaplace(6/s^4) % Inverse Laplace transform. >> syms x w >> fourier(-2*pi*abs(x)) % Fourier transform.

  >> ifourier(4*pi/w^2) % Inverse Fourier transform. >> quit % Exit MATLAB. >> % End of Tutorial 1.

1.2 Tutorial Two: Plots and Differential Equations (1 h)

  More involved plots will be dealt with in Sect. 

  ou will need the Symbolic Math Toolbox for most of the commands in this section.

  MATLAB Commands >> % Plotting graphs.

  >> % Set up the domain and plot a simple function. >> x=-2:.01:2; >> plot(x,x.^2) >> % Plot two curves on one graph and label them.

  >> t=0:.1:100; >> y1=exp(-.1.*t).*cos(t);y2=cos(t); >> plot(t,y1,t,y2),legend(’y1’,’y2’) >> % Plotting with the Symbolic Math Toolbox.

  >> ezplot(’x^2’,[-2,2]) >> % Plot with labels and title. >> ezplot(’exp(-t)*sin(t)’),xlabel(’time’),ylabel(’current’), title(’decay’) >> % Contour plot on a grid of 50 by 50. >> ezcontour(’y^2/2-x^2/2+x^4/4’,[-2,2],50) >> % Surface plot. Rotate the plot using the mouse. >> ezsurf(’y^2/2-x^2/2+x^4/4’,[-2,2],50) >> % Combined contour and surface plot. >> ezsurfc(’y^2/2-x^2/2+x^4/4’,[-2,2])

  >> ezplot(’t^3-4*t’,’t^2’,[-3,3]) >> % 3-D parametric curve. >> ezplot3(’sin(t)’,’cos(t)’,’t’,[-10,10]) >> % Implicit plot.

  >> ezplot(’2*x^2+3*y^2-12’)

  Symbolic Solutions to Ordinary Differential Equations (ODEs). If an analytic solution cannot be found, the message “Warning: Explicit solution could not be found” is shown.

  >> % The D denotes differentiation with respect to t. >> dsolve(’Dx=-x/t’) >> % An initial value problem.

  >> dsolve(’Dx=-t/x’,’x(0)=1’) >> % A second order ODE. >> dsolve(’D2x+5*Dx+6*x=10*sin(t)’,’x(0)=0’,’Dx(0)=0’) >> % A linear system of ODEs. >> [x,y]=dsolve(’Dx=3*x+4*y’,’Dy=-4*x+3*y’) >> % A system with initial conditions. >> [x,y]=dsolve(’Dx=x^2’,’Dy=y^2’,’x(0)=1,y(0)=1’) >> % A 3-D linear system. >> [x,y,z]=dsolve(’Dx=x’,’Dy=y’,’Dz=-z’)

  Numerical Solutions to ODEs. These methods are usually used when an analytic solution cannot

  be found—even though one may exist! Below is a Table

   lists some initial value problem solvers in MATLAB. See the on-line MATLAB index for more details or type >> help topic.

Table 1.1 There are other solvers, but the solvers listed below should suffice for the material covered in this book

  Solver O.D.E Method Summary ode45 Nonstiff Runge–Kutta Try this first ode23 Nonstiff Runge–Kutta Crude tolerances ode113 Nonstiff Adams Multi-step solver ode15s Stiff Gears method If you suspect stiffness ode23s Stiff Rosenbrock One step solver

  >> % Set up a 1-D system with initial condition 50, >> % and run for 0<t<100.

  >> deq1=@(t,x) x(1)*(.1-.01*x(1)); >> [t,xa]=ode45(deq1,[0 100],50); >> plot(t,xa(:,1)) >> % A 2-D system with initial conditions [.01,0], >> % and run for 0<t<50.

  >> deq2=@(t,x) [.1*x(1)+x(2);-x(1)+.1*x(2)]; >> [t,xb]=ode45(deq2,[0 50],[.01,0]); >> plot(xb(:,1),xb(:,2)) >> % A 3-D system with initial conditions.

  >> deq3=@(t,x) [x(3)-x(1);-x(2);x(3)-17*x(1)+16]; >> [t,xc]=ode45(deq3,[0 20],[.8,.8,.8]); >> plot3(xc(:,1),xc(:,2),xc(:,3))

  >> deq4=@(t,x) [x(2);1000*(1-(x(1))^2)*x(2)-x(1)]; >> [t,xd]=ode23s(deq4,[0 3000],[.01,0]); >> plot(xd(:,1),xd(:,2)) >> % Displacement against time.

  >> plot(t,xd(:,1)) >> % End of Tutorial 2.

1.3 MATLAB Program Files or M-Files

  Sections

  llustrate the use of the Command Window and its interactive nature. More

  involved tasks will require more lines of code, and it is better to use MATLAB program files or M- files. Each program is displayed between horizontal lines and kept short to aid in understanding; the output is also included.

  Function M-Files. The following M-file defines the logistic function.

  % Program 1 - The logistic function. % Save the M-file as fmu.m. function y=fmu(mu,x) y=mu*x*(1-x); % End of Program 1. >> fmu(2,.1) ans = 0.1800

  The for..end Loop. For repetitive tasks.

  % Program 2 - The Fibonacci sequence. % Save the M-file as Fibonacci.m. Nmax=input(’Input the number of terms of the Fibonacci sequence:’) F=zeros(1,Nmax); F(1)=1;F(2)=1; for i=3:Nmax F(i)=F(i-1)+F(i-2); end F % End of Program 2.

  >>Fibonacci Input the number of terms of the Fibonacci sequence:10 Nmax=10 F = 1 1 2 3 5 8 13 21 34 55 Conditional Statements. If..then..elseif..else..end, etc.

  % Program 3 - The use of logical expressions. % Save this M-file as test1.m. integer=input(’Which integer do you wish to test?’) if integer == 0 disp([’The integer is zero.’]) elseif integer < 0 disp([’The integer is negative.’]) disp([’The integer is positive.’]) end % End of Program 3. >> test1 Which integer do you wish to test?-100 integer=-100 The integer is negative.

  Fig. 1.2 A multiple plot with text Graphic Programs. Multiple plots with text (Fig.  .

  % Program 4 - Two curves on one graph. % Save the M-file as plot1.m. % Tex symbols can be plotted within a figure window. clear all fsize=15; x=0:.1:7; figure; plot(x,2*x./5,x,-x.^2/6+x+7/6) text(1,2,’\leftarrow curve 1’,’Fontsize’,fsize) text(2.6,1,’\leftarrow line 1’,’Fontsize’,fsize) xlabel(’x’,’Fontsize’,fsize); ylabel(’y’,’Fontsize’,fsize) title(’Two curves on one plot’,’Fontsize’,fsize) % End of Program 4. >> plot1

  Labeling Solution Curves. Solutions to the pendulum problem (Fig.  .

  % Program 5 - Solution curves to different ODEs. % Save M-file as deplot1.m. clear; figure; hold on deqn=@(t,x) [x(2);-25*x(1)]; plot(t,xa(:,1),’r’); % Plot a red curve. clear deqn=@(t,x) [x(2);-2*x(2)-25*x(1)]; [t,xb]=ode45(deqn,[0 10],[1 0]); plot(t,xb(:,1),’b’); % Plot a blue curve. legend(’harmonic motion’,’damped motion’) xlabel(’time’,’Fontsize’,15); ylabel(’displacement’,’Fontsize’,15); hold off % End of Program 5. >> deplot1

  Fig. 1.3 Harmonic and damped motion of a pendulum Echo Commands. Useful when debugging a program.

  % Program 6 - Use echo to display command lines. % Save the M-file as poincare.m. echo on r(1)=1; for n=2:5 r(n)=r(n-1)/(1+2*pi*r(n-1)) end echo off % End of Program 6. >> poincare r(n)=r(n-1)/(1+2*pi*r(n-1)) r = 1.0000 0.1373 0.0737 0.0504 0.0383

1.4 Hints for Programming

  The MATLAB language contains very powerful commands, which means that some complex programs may contain only a few lines of code. Of course, the only way to learn programming is to sit down and try it yourself. This section has been included to point out common errors and give advice following does not help you with your particular problem.

  Common Typing Errors. The author strongly advises new users to run Tutorials One and Two in

  the Command Window environment, this should reduce typing errors.

  Be careful to include all mathematics operators. When dealing with vectors put a full stop (.) in front of the mathematical operator. Make sure brackets, parentheses, etc. match up in correct pairs. Remember MATLAB is case-sensitive. Check the syntax, enter help followed by the name of the command.

  Programming Tips. The reader should use the M-files in Sect.  o practice simple

  programming techniques. Note that MATLAB has a built in code analyzer and appears in the top right corner of the message bar. Red indicates syntax errors were detected. Orange indicates warnings or opportunities for improvement, but no errors, were detected, and green indicates no errors, warnings, or opportunities for improvement were detected. For more information and examples, the reader should check the MathWorks document center for checking code for errors and warnings.

  It is best to clear values at the start of a large program. Use the figure command when creating a new figure. Preallocate arrays to prevent MATLAB from having to continually re-size arrays—for example, use the zeros command. An example is given in Program 2 above.

  Vectorize where possible. Convert for and while loops to equivalent vector or matrix operations. If a program involves a large number of iterations, for example 50,000, then run it for three iterations first of all and use the echo command. If the computer is not responding hold Ctrl+C and try reducing the size of the problem. Click on the green play Run in the M-file Window, MATLAB will list any error messages. Find a similar M-file in a book or on the Web, and edit it to meet your needs. Make sure you have the correct packages, for example, the symbolic commands will not work if you do not have the Symbolic Math Toolbox. Check which version of MATLAB you are using.

1.5 MATLAB Exercises

  1. Evaluate the following: (a) ;

  12

  (b) 3 ;

  (c) sin(0. 1π); (d) ; (e) .

  2. Given that determine the following: (a) A + 4BC; (b) the inverse of each matrix if it exists;

  3

  (c)

  A ;

  (d) the determinant of C; (e) the eigenvalues and eigenvectors of B.

  3. Given that , , and , evaluate the following: (a) ;

  (b) ; (c) ; (d) ln(z );

  1 (e) sin(z ).

  3

  4. Evaluate the following limits if they exist: (a)

  ; (b)

  ; (c)

  ; (d)

  ; (e) .

  5. Find the derivatives of the following functions: (a)

  ; (b)

  ;

  x

  (c)

  y = e sinxcosx;

  (d) y = tanhx; (e) .

  6. Evaluate the following definite integrals: (a)

  ; (b)

  ; (c)

  ; (d)

  ; (e) .

  7. Graph the following: (a)

  ; (b)

  , for − 5 ≤ x ≤ 5; (c)

  ; (d)

  , for − 3 ≤ x ≤ 3 and − 1 ≤ y ≤ 1; (e) , , for − 4 ≤ t ≤ 4.

  8. Solve the following differential equations: (a)

  , given that y(1) = 1; (b)

  , given that y(2) = 3; (c)

  , given that y(0) = 1;

  (d) , given that x(0) = 1 and ;

  (e) , given that x(0) = 1 and .

  9. Carry out one hundred iterations on the recurrence relation given that (a) x  = 0. 2 and (b) x  = 0. 2001. List the final ten iterates in each case.

  10. Type “help while” after the >> prompt to read information on the while command. Use a while loop to program Euclid’s algorithm for finding the greatest common divisor of two integers. Use your program to find the greatest common divisor of 12,348 and 14,238.

  References

  1. S. Attaway, MATLAB: A Practical Introduction to Programming and Problem Solving, 2nd edn. (Butterworth-Heinemann, Newton, 2011)

  

2. O. Demirkaya, M.H. Asyali, P.K. Sahoo, Image Processing with MATLAB: Applications in Medicine and Biology (CRC Press,

New York, 2008)

  3. D.G. Duffy, Advanced Engineering Maths with MATLAB, 3rd edn. (CRC Press, New York, 2010)

  4. A. Gilat, MATLAB: An Introduction with Applications, 5th edn. (Wiley, New York, 2014)

  5. B.R. Hunt, R.L. Lipman, J.M. Rosenberg, A Guide to MATLAB: For Beginners and Experienced Users, 3rd edn. (Cambridge University Press, Cambridge, 2014)

  6. H. Moore, MATLAB for Engineers, 2nd edn. (Prentice-Hall, Upper Saddle River, 2008)

  7. R. Pratab, MATLAB: Getting Started with MATLAB: A Quick Introduction for Scientists and Engineers (Oxford University Press, Oxford, 2009)

  8. M. Shahin, Explorations of Mathematical Models in Biology with MATLAB (Wiley-Blackwell, New York, 2014)

  9. A. Siciliano, Matlab: Data Analysis and Visualization (World Scientific, Singapore, 2008)

  10. A.K. Tyagi, MATLAB and Simulink for Engineers (Oxford University Press, London, 2012)

  © Springer International Publishing Switzerland 2014 Stephen Lynch, Dynamical Systems with Applications using MATLAB®, DOI 10.1007/978-3-319-06820-6_2

  2. Linear Discrete Dynamical Systems 1 Stephen Lynch

  (1) Department of Computing and Mathematics, Manchester Metropolitan University School of Computing, Mathematics & Digital Technology, Manchester, UK

  Aims and Objectives

  To introduce recurrence relations for first- and second-order difference equations To introduce the theory of the Leslie model To apply the theory to modeling the population of a single species

  On completion of this chapter, the reader should be able to solve first- and second-order homogeneous linear difference equations; find eigenvalues and eigenvectors of matrices; model a single population with different age classes; predict the long-term rate of growth/decline of the population; investigate how harvesting and culling policies affect the model. This chapter deals with linear discrete dynamical systems, where time is measured by the number of iterations carried out and the dynamics are not continuous. In applications this would imply that the solutions are observed at discrete time intervals.

  Recurrence relations can be used to construct mathematical models of discrete systems. They are also used extensively to solve many differential equations which do not have an analytic solution; the differential equations are represented by recurrence relations (or difference equations) that can be solved numerically on a computer. Of course one has to be careful when considering the accuracy of the numerical solutions. Ordinary differential equations are used to model continuous dynamical systems later in the book.

  The bulk of this chapter is concerned with a linear discrete dynamical system that can be used to model the population of a single species. As with continuous systems, in applications to the real world, linear models generally produce good results over only a limited range of time. The Leslie model introduced here is useful when establishing harvesting and culling policies. Nonlinear discrete dynamical systems will be discussed in the next chapter.

  The Poincaré maps introduced in Chap. 

  or example, illustrates how discrete systems can be used to help in the understanding of how continuous systems behave.

2.1 Recurrence Relations

  This section is intended to give the reader a brief introduction to difference equations and illustrate the theory with some simple models.

  First-Order Difference Equations

  A recurrence relation can be defined by a difference equation of the form (2.1) where x is derived from x and n = 0, 1, 2, 3, . If one starts with an initial value, say, x , then

  n+1 n iteration of ( leads to a sequence of the form In applications, one would like to know how this sequence can be interpreted in physical terms.

  Equations of the form (

   ) are called first-order difference equations because the suffices differ by one. Consider the following simple example.