MatLab - Systems of Differential Equations



Similar documents
[1] Diagonal factorization

MATH APPLIED MATRIX THEORY

WEEK #3, Lecture 1: Sparse Systems, MATLAB Graphics

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial VI

HW6 Solutions. MATH 20D Fall 2013 Prof: Sun Hui TA: Zezhou Zhang (David) November 14, Checklist: Section 7.8: 1c, 2, 7, 10, [16]

Beginner s Matlab Tutorial

Nonlinear Systems of Ordinary Differential Equations

x = + x 2 + x

GeoGebra. 10 lessons. Gerrit Stols

MAT 242 Test 2 SOLUTIONS, FORM T

Brief Introduction to Vectors and Matrices

MATH 423 Linear Algebra II Lecture 38: Generalized eigenvectors. Jordan canonical form (continued).

Linear Algebra and TI 89

Eigenvalues, Eigenvectors, and Differential Equations

Similarity and Diagonalization. Similar Matrices

x y The matrix form, the vector form, and the augmented matrix form, respectively, for the system of equations are

Gerrit Stols

3.2 Sources, Sinks, Saddles, and Spirals

Applied Linear Algebra

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

Updates to Graphing with Excel

Scientific Graphing in Excel 2010

Math 115A HW4 Solutions University of California, Los Angeles. 5 2i 6 + 4i. (5 2i)7i (6 + 4i)( 3 + i) = 35i + 14 ( 22 6i) = i.

This activity will show you how to draw graphs of algebraic functions in Excel.

By Clicking on the Worksheet you are in an active Math Region. In order to insert a text region either go to INSERT -TEXT REGION or simply

Eigenvalues and Eigenvectors

Solutions to Math 51 First Exam January 29, 2015

MAT 200, Midterm Exam Solution. a. (5 points) Compute the determinant of the matrix A =

Excel -- Creating Charts

Lecture Notes 2: Matrices as Systems of Linear Equations

Examination paper for TMA4115 Matematikk 3

by the matrix A results in a vector which is a reflection of the given

Au = = = 3u. Aw = = = 2w. so the action of A on u and w is very easy to picture: it simply amounts to a stretching by 3 and 2, respectively.

Linear Equations ! $ & " % & " 11,750 12,750 13,750% MATHEMATICS LEARNING SERVICE Centre for Learning and Professional Development

Dealing with Data in Excel 2010

Chapter 6. Orthogonality

Pre-Calculus Math 12 First Assignment

Name: Section Registered In:

Graphing in excel on the Mac

Manifold Learning Examples PCA, LLE and ISOMAP

Solving Systems of Equations Using Mathcad Charles Nippert Solving A System of Equations By Symbolically Figure 1 After Step 1

Dynamical Systems Analysis II: Evaluating Stability, Eigenvalues

Scatter Plots with Error Bars

1.5 SOLUTION SETS OF LINEAR SYSTEMS

CHAPTER 2. Eigenvalue Problems (EVP s) for ODE s

Introduction to COMSOL. The Navier-Stokes Equations

Euler s Method and Functions

What is a piper plot?

Introduction to the TI-Nspire CX

DATA ANALYSIS II. Matrix Algorithms

Linear Algebra Review. Vectors

Nonlinear Algebraic Equations Example

Several Views of Support Vector Machines

Student name: Earlham College. Fall 2011 December 15, 2011

Interactive Excel Spreadsheets:

Orthogonal Diagonalization of Symmetric Matrices

Chapter 17. Orthogonal Matrices and Symmetries of Space

Data representation and analysis in Excel

Review of Fundamental Mathematics

Quick Tour of Mathcad and Examples

2x + y = 3. Since the second equation is precisely the same as the first equation, it is enough to find x and y satisfying the system

Part 1: Background - Graphing

Systems of Equations

Plots, Curve-Fitting, and Data Modeling in Microsoft Excel

Tutorial on Using Excel Solver to Analyze Spin-Lattice Relaxation Time Data

Manual for simulation of EB processing. Software ModeRTL

PGR Computing Programming Skills

Figure 1. An embedded chart on a worksheet.

5 Systems of Equations

Introduction to Matrix Algebra

Numerical Methods for Differential Equations

CS 221. Tuesday 8 November 2011

Eigenvalues, Eigenvectors, Matrix Factoring, and Principal Components

Linear Equations in Linear Algebra

I. Turn it on: Press É

Complex Eigenvalues. 1 Complex Eigenvalues

Lecture 5: Singular Value Decomposition SVD (1)

x + y + z = 1 2x + 3y + 4z = 0 5x + 6y + 7z = 3

Graphing Equations. with Color Activity

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors

7.7 Solving Rational Equations

Absorbance Spectrophotometry: Analysis of FD&C Red Food Dye #40 Calibration Curve Procedure

Intermediate PowerPoint

Summary: Transformations. Lecture 14 Parameter Estimation Readings T&V Sec Parameter Estimation: Fitting Geometric Models

System of First Order Differential Equations

The Heat Equation. Lectures INF2320 p. 1/88

A First Course in Elementary Differential Equations. Marcel B. Finan Arkansas Tech University c All Rights Reserved

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

Systems of Linear Equations

( ) which must be a vector

Graphics in R. Biostatistics 615/815

LS.6 Solution Matrices

Grade level: secondary Subject: mathematics Time required: 45 to 90 minutes

MATH 304 Linear Algebra Lecture 9: Subspaces of vector spaces (continued). Span. Spanning set.

Introduction. Chapter 1

2.2 Derivative as a Function

Transcription:

Fall 2015 Math 337 MatLab - Systems of Differential Equations This section examines systems of differential equations. It goes through the key steps of solving systems of differential equations through the numerical methods of MatLab along with its graphical solutions. The system of differential equations is introduced. Analysis begins with finding equilibria. Near an equilibrium the linear behavior is most important, which requires studying eigenvalue problems. Numerical routines can simulate the system of differential equations, while the special routine pplane allows easy study of the system with excellent graphics. The general two dimensional autonomous system of differential equations in the state variables x 1 t and x 2 t can be written: ẋ 1 = f 1 x 1,x 2, ẋ 2 = f 2 x 1,x 2, where the functions f 1 and f 2 may be nonlinear. This section will concentrate on the case when f 1 and f 2 are linear to parallel the lecture notes, Systems of Two First Order Equations. The Greenhouse/Rockbed Model from the lecture notes is given by the linear system of differential equations: u1 u 2 13 8 = 3 1 1 u1 u 2 + 1 0 This example will provide the primary case for our MatLab commands listed below. Equilibria Equilibria occur when the derivative is zero. In the general case where the right hand side of the system of differential equations is nonlinear, this problem can be very complex. However, when the functions f 1 and f 2 are linear, then finding equilibria reduces to solving a linear system of equations. This is very basic for MatLab and can be accomplished in a number of ways. For the greenhouse/rockbed model above, the equilibrium model satisfies: This is more simply written: 13 8 3 1 1 u1e u 2e Au e = b, = 1 0.. 1 where A is the matrix of coefficients, u e is the equilibrium solution, and b is the nonhomogeneous vector from the external environment. Below we provide three ways in MatLab to find u e, the equilibrium solution. The two most common means to solving this linear system are to use the program linsolve or to take advantage of MatLab s ability to invert a matrix. Define the variables, then the following commands readily provide the solution. A = [-13/8 3/;1/ -1/]; b = [-1;0]; u = linsolvea,b u = inva*b

Both results produce the variable u = [,] T for the equilibrium solution. The third method is to use the row-reduced echelon form for transforming an augmented matrix into the identity with the solution in the last column. The MatLab program for this is rref. There used to be a common teaching tool called rrefmovie, which showed all the steps of the process including the names of the operation, but this function appears to have been removed after Version 10 of MatLab. Below we show the commands necessary for this solution method. B = [A,b] rrefb The results are the following: [ 1.6250 0.7500 1.0000 B = 0.2500 0.2500 0 ] [ 1 0 0 1 ] Linear Analysis As noted in the lecture notes, Systems of Two First Order Equations, the original state variable, u, is translated to the new state variable, v = u u e, resulting in the new linear system of differential equations centered at the origin: or more simply v1 v 2 13 8 = 3 1 1 v = Av. v1 For this problem we seek solutions vt = ξe λt, and the result is the eigenvalue problem: A λiξ = 0, where det A λi = 0, provides the characteristic equation for the eigenvalues and ξ are the corresponding eigenvectors. For this system with distinct real eigenvalues, λ 1 and λ 2, and corresponding eigenvectors, ξ 1 and ξ 2, the solution of System 2 satisfies: v 2 vt = c 1 ξ 1 e λ 1t +c 2 ξ 2 e λ 2t, where c 1 and c 2 are arbitrary constants. Once again MatLab is an excellent program for solving this eigenvalue problem. The MatLab command [v,d] = eiga produces the eigenvalues on the diagonal of matrix d with the corresponding eigenvectors appearing as columns of matrix v. For this example MatLab produces: [ ] [ ] 1.7500 0 0.986 0.72 d = v =, 3 0 0.1250 0. 0.89 which gives the general solution to System 2 as 0.986 vt = c 1 e 1.75t 0.72 +c 0. 2 0.89 e 0.125t. 2

Solution to the System of Linear Differential Equations Since ut = vt+u e, it follows that the general solution to 1 is ut = c 1 0.986 0. e 1.75t +c 2 0.72 0.89 e 0.125t + Thespecificsolution toaninitial valueproblem, whereu0 = u 0, isreadilyfoundusingmatlab and solving the vector equation: c 1 ξ 1 +c 2 ξ 2 +u e = u 0. We use our example above with u 0 = [5,25] T or v 0 = [ 11,9] T to illustrate the appropriate MatLab commands. Assume that the eigenvectors are stored in v as presented in 3. Let c = [c 1,c 2 ] T be vector for which MatLab is solving, then v0 = [-11, 9] ; c = linsolvev,v0 produces the solution c = [1.5050, 7.3962] T, so the unique solution to the IVP is ut = 1.5050 0.986 0. e 1.75t +7.3962 0.72 0.89 e 0.125t +. The MatLab s numerical solver, ode23, extends easily to systems of 1 st order differential equations. Below we show how to both use the numerical solver and the exact solution above to graph the ut. First the right hand side of System 1 is made into a MatLab function 1 function yp = greenhouset,y 2 % Greenhouse DE rhs 3 yt1 = 13/8 y1 +3/ y2 + 1; yt2 = 1/ y1 1/ y2 ; 5 yp = [yt1, yt2 ] ; 6 end The function plotting the numerical and exact solutions is given by 1 mytitle = Greenhouse/Rockbed ; % Title 2 xlab = $t$ hrs ; % X label 3 ylab = Temperature $ˆ\circ$C ; % Y label 5 u0 = [5,25] ; 6 [t,u] = ode23@greenhouse,[0,10],u0 ; % simulate heat with ode23 7 tt = linspace 0,10,200 ; 8 u1 = 1.3077 exp 1.75 tt +3.3077 exp 0.125 tt +; % solution u1 9 u2 = 2.386 exp 1.75 tt+6.615 exp 0.125 tt+; % solution u2 10 11 plot t,u:,1, b, LineWidth,1.5 ; % Plot greenhouse air numeric 12 hold on % Plots Multiple graphs 13 plot t,u:,2, r, LineWidth,1.5 ; % Plot greenhouse rocks numeric 1 plot tt,u1, c:, LineWidth,1.5 ; % Plot greenhouse air, u1 15 plot tt,u2, m:, LineWidth,1.5 ; % Plot greenhouse rocks, u2 plot [0 10],[ ], k:, LineWidth,1.5 ; % Plot equilibrium 17 grid % Adds Gridlines 18 text 0.6,11, $u 1$, color, blue, FontSize,1,....

19 FontName, Times New Roman, interpreter, latex ; 20 text 3,22, $u 2$, color, red, FontSize,1,... 21 FontName, Times New Roman, interpreter, latex ; 22 legend Air numeric, Rockbed numeric, Air exact,... 23 Rockbed exact, ; 2 25 axis [0 10 0 30] ; % Defines limits of graph 30 Greenhouse/Rockbed 25 u 2 Temperature C 20 15 10 u 1 5 Air numeric Rockbed numeric Air exact Rockbed exact 0 0 1 2 3 5 6 7 8 9 10 t hrs The graph shows how well the numerical routine ode23 in MatLab tracks the solution to System 1. As we saw in the lecture notes, the heat transfers rapidly into the air compartment, then slowly the solution tends toward the equilibrium solution. Phase Portrait - 2D This final section shows how to create two dimensional phase portraits and direction fields. You begin by downloading the MatLab files for pplane and dfield by John Polking from Rice University. The current version is pplane8, which is invoked by having this m-file in your current directory and typing pplane8 in the command window of MatLab. After invoking pplane8 a window appears where you type in your differential equation, including the limits on your state variables. This will generate a new window showing the direction field for the phase portrait. With the mouse you can click at any point and have a solution trajectory be drawn. Default for this is both directions in time. To get a forward trajectory only one select Solution direction under the Options menu. One of the most powerful features is the ability of this program to find equilibria and determine the eigenvalues near that equilibrium. This feature is found under the Solutions menu saying Find an equilibrium point. Select this feature, then click on the graph where you think an equilibrium point may be. A large red dot

appears at the equilibrium, and a new window opens telling the coordinates of the equilibrium, the nature of the equilibrium, and the eigenvalues and eigenvectors of the linearized system near the equilibrium. Another useful feature under the Solutions menu is to Show nullclines. The nullclines tell where trajectories are either horizontal or vertical. The intersection of two different color nullclines shows the location of an equilibrium. Below is a figure showing the direction field for our example. Four solutions were added along with the equilibrium and the nullclines. Nonlinear Example The pplane8 program is particularly useful for systems of two nonlinear differential equations. A competition model for two species y 1 and y 2 competing for the same resource satisfies the following system of differential equations: ẏ 1 = 0.1y 1 1 0.022y 1 0.03y 2, ẏ 2 = 0.12y 2 1 0.037y 1 0.02y 2. Though it is not the case for this system of differential equations, it can be quite challenging finding the equilibria for a nonlinear system of differential equations. MatLab does have a powerful tool for solving nonlinear systems of equations to find where they are zero, and it is called fsolve. The MatLab function fsolve requires entering a function fx, which can be a vector function, and an initial guess, x 0, then it tries to find the closest x that solves fx = 0. If we define the right hand side of the DE above as the following MatLab function: 1 function z = compet y 2 % competition model: fsolve for equilibria 3 zt1 = 0.1 y1 1 0.022 y1 0.03 y2 ; zt2 = 0.12 y2 1 0.037 y1 0.02 y2 ; 5 z = [ zt1, zt2 ]; 6 end

If we enter the following in MatLab: ye = fsolve@compet,[10,20]; then MatLab gives the unstable equilibrium y e = [10.3093,25.7732] T. There are 3 other equilibria, which could be found by similarly using our compet function with different initial guesses. More easily, one can employ pplane as noted above. It readily finds equilibria and the eigenvalues associated with each equilibrium. For example, pointing near y e = [10.3093,25.7732] T, pplane8 finds this equilibrium, and tells you that it is a saddle node with eigenvalues λ 1 = 0.038 and λ 2 = 0.1133 along with their corresponding eigenvectors. Below we show the figure produced by pplane8.