Solving systems of first order equations with ode Systems of first order differential equations.

Similar documents
Chapter 1: Introduction

Problem set 7 Math 207A, Fall 2011 Solutions

Department of Mathematics IIT Guwahati

MATH 215/255 Solutions to Additional Practice Problems April dy dt

Nonlinear Autonomous Systems of Differential

Exam 2 Study Guide: MATH 2080: Summer I 2016

Computer Problems for Methods of Solving Ordinary Differential Equations

Math 266: Phase Plane Portrait

Chapter 6 Nonlinear Systems and Phenomena. Friday, November 2, 12

FIRST-ORDER ORDINARY DIFFERENTIAL EQUATIONS II: Graphical and Numerical Methods David Levermore Department of Mathematics University of Maryland

8. Qualitative analysis of autonomous equations on the line/population dynamics models, phase line, and stability of equilibrium points (corresponds

Vector Fields and Solutions to Ordinary Differential Equations using MATLAB/Octave

Mathematical Computing

Parametric Equations, Vectors, and Vector Valued Functions. Different parametric equations can yield the same curve:

= 2e t e 2t + ( e 2t )e 3t = 2e t e t = e t. Math 20D Final Review

Exam 1 Review SOLUTIONS

Math 232, Final Test, 20 March 2007

. For each initial condition y(0) = y 0, there exists a. unique solution. In fact, given any point (x, y), there is a unique curve through this point,

Why are Discrete Maps Sufficient?

A plane autonomous system is a pair of simultaneous first-order differential equations,

Final Exam Sample Problems, Math 246, Spring 2018

1 The pendulum equation

Section 1.3 Integration

1.2. Direction Fields: Graphical Representation of the ODE and its Solution Let us consider a first order differential equation of the form dy

Calculus for the Life Sciences II Assignment 6 solutions. f(x, y) = 3π 3 cos 2x + 2 sin 3y

(p) p(y) = (e) g(t) = (t + t 2 )(1 5t + 4t 2 ) (r) x(t) = sin(t) cos(t) tan(t) (s) f(x) = x ( 3 x + 5 x) (t) f(x) = 1 2 (x ) (u) f(x) = 4x3 3x 2

MATH 280 Multivariate Calculus Fall Integrating a vector field over a curve

Nonlinear Oscillators: Free Response

Understand the existence and uniqueness theorems and what they tell you about solutions to initial value problems.

Math 215/255 Final Exam, December 2013

STABILITY. Phase portraits and local stability

4 Second-Order Systems

System Control Engineering 0

154 Chapter 9 Hints, Answers, and Solutions The particular trajectories are highlighted in the phase portraits below.

Solution. Your sketch should show both x and y axes marked from 5 to 5 and circles of radius 1, 3, and 5 centered at the origin.

Appendix 3B MATLAB Functions for Modeling and Time-domain analysis

Solutions of the Sample Problems for the First In-Class Exam Math 246, Fall 2017, Professor David Levermore

+ i. cos(t) + 2 sin(t) + c 2.

Answers and Hints to Review Questions for Test (a) Find the general solution to the linear system of differential equations Y = 2 ± 3i.

Math 308 Week 8 Solutions

MATH 251 Final Examination December 16, 2015 FORM A. Name: Student Number: Section:

CHAPTER 7. An Introduction to Numerical Methods for. Linear and Nonlinear ODE s

Coordinate Curves for Trajectories

Differentiation of Parametric Space Curves. Goals: Velocity in parametric curves Acceleration in parametric curves

FINAL EXAM MATH303 Theory of Ordinary Differential Equations. Spring dx dt = x + 3y dy dt = x y.

Math Homework 3 Solutions. (1 y sin x) dx + (cos x) dy = 0. = sin x =

Math 251 December 14, 2005 Answer Key to Final Exam. 1 18pt 2 16pt 3 12pt 4 14pt 5 12pt 6 14pt 7 14pt 8 16pt 9 20pt 10 14pt Total 150pt

Name: MA 226 Exam 2 Show Your Work and JUSTIFY Your Responses. Problem Possible Actual Score TOTAL 100

1 The relation between a second order linear ode and a system of two rst order linear odes

MATH 200 WEEK 5 - WEDNESDAY DIRECTIONAL DERIVATIVE

Additional Homework Problems

Solutions to Math 53 Math 53 Practice Final

Solutions to Final Exam Sample Problems, Math 246, Spring 2011

University of Toronto FACULTY OF APPLIED SCIENCE AND ENGINEERING FINAL EXAMINATION, JUNE, 2012 First Year - CHE, CIV, IND, LME, MEC, MSE

Differential Equations Spring 2007 Assignments

Math 215/255 Final Exam (Dec 2005)

Homework Solutions:

Differential Equations: Homework 8

Solutions of Math 53 Midterm Exam I

MATH 308 Differential Equations

Matlab Problem Sets. Math 246 Spring 2012 Sections 0112, 0122, 0132, R. Lipsman

Lecture 20/Lab 21: Systems of Nonlinear ODEs

Name: Problem Possible Actual Score TOTAL 180

Introduction to Dynamical Systems

MATH 415, WEEKS 7 & 8: Conservative and Hamiltonian Systems, Non-linear Pendulum

AP Calculus (BC) Chapter 10 Test No Calculator Section. Name: Date: Period:

Section 1.8/1.9. Linear Transformations

Math 1270 Honors ODE I Fall, 2008 Class notes # 14. x 0 = F (x; y) y 0 = G (x; y) u 0 = au + bv = cu + dv

Math 251 December 14, 2005 Final Exam. 1 18pt 2 16pt 3 12pt 4 14pt 5 12pt 6 14pt 7 14pt 8 16pt 9 20pt 10 14pt Total 150pt

True or False. Circle T if the statement is always true; otherwise circle F. for all angles θ. T F. 1 sin θ

Entrance Exam, Differential Equations April, (Solve exactly 6 out of the 8 problems) y + 2y + y cos(x 2 y) = 0, y(0) = 2, y (0) = 4.

3.2 Systems of Two First Order Linear DE s

Lecture 9. Systems of Two First Order Linear ODEs

Math 216 Second Midterm 20 March, 2017

Numerical methods for solving ODEs

Chapter #4 EEE8086-EEE8115. Robust and Adaptive Control Systems

Math 312 Lecture Notes Linearization

Math 216 First Midterm 18 October, 2018

ẋ = f(x, y), ẏ = g(x, y), (x, y) D, can only have periodic solutions if (f,g) changes sign in D or if (f,g)=0in D.

Section 8.4 Plane Curves and Parametric Equations

CDS 101 Precourse Phase Plane Analysis and Stability

Section 14.1 Vector Functions and Space Curves

NORTHEASTERN UNIVERSITY Department of Mathematics

MA 226 FINAL EXAM. Show Your Work. Problem Possible Actual Score

Math 116 Practice for Exam 2

APPM 2360: Final Exam 10:30am 1:00pm, May 6, 2015.

Volumes of Solids of Revolution Lecture #6 a

Do not turn over until you are told to do so by the Invigilator.

Math 23: Differential Equations (Winter 2017) Midterm Exam Solutions

Answer Key b c d e. 14. b c d e. 15. a b c e. 16. a b c e. 17. a b c d. 18. a b c e. 19. a b d e. 20. a b c e. 21. a c d e. 22.

Ideas from Vector Calculus Kurt Bryan

Introduction to Mathematica and Graphing in 3-Space

Problem Score Possible Points Total 150

Plane Curves and Parametric Equations

Matlab Sheet 3 - Solution. Plotting in Matlab

Linear Algebra Using MATLAB

Section 6: Summary Section 7

spring mass equilibrium position +v max

3.3. SYSTEMS OF ODES 1. y 0 " 2y" y 0 + 2y = x1. x2 x3. x = y(t) = c 1 e t + c 2 e t + c 3 e 2t. _x = A x + f; x(0) = x 0.

Transcription:

A M S 20 MA TLA B NO T E S U C S C Solving systems of first order equations with ode45 c 2015, Yonatan Katznelson The M A T L A B numerical solver, ode45 is designed to work with first order differential equations and systems of first order equations We have already seen how to find approximate solutions to a single, first-order initial value problem, and the procedure for systems of first order equations is completely analogous First a brief summary of systems of first order equations and initial value problems 1 Systems of first order differential equations A system of first order differential equations looks like this: y 1 = f 1 (t, y 1, y 2,, y k ) y 2 = f 2 (t, y 1, y 2,, y k ) y k = f k (t, y 1, y 2,, y k ) (11) where y 1, y 2,, y k are interrelated functions A first order system like (11) may be accompanied by initial values y 1 (t 0 ) = η 1, y 2 (t 0 ) = η 2,, y k (t 0 ) = η k, giving a (k-dimensional) initial value problem A better way to view a system of first order equations like (11) is as a single vector-valued equation y = F(t, y), (12) where y = y 1 y 2 y k, y = y 1 y 2 y k and F = This is the way that M A T L A B views things In this format, an initial value problem looks like y = F(t, y), y(t 0 ) = η, where η = η 1 η 2 η k f 1 f 2 f k 2 Using ode45 to solve vector-valued initial value problems Recall that to compute an approximate solution to the single (scalar-valued) initial value problem y = f(t, y), y(t 0 ) = y 0 on the interval [t 0, t 1 ], we use the M A T L A B commands 1

>> f=@(t,y) (definition of f(t, y)); >> [t y] = ode45(f,[t 0 t 1 ],y 0 ); To find the approximate solutions to vector-valued, first order initial value problems, the syntax is almost identical, except that we have to remember that the variables and functions are now (column) vectors Specifically, to compute an approximate solution to the vector-valued initial value problem y 1 f 1 (t, y 1,, y k ) y 1 (t 0 ) η 1 y 2 f 2 (t, y 1,, y k ) y 2 (t 0 ) η 2 y k = f k (t, y 1,, y k ) ; on the interval [t 0, t 1 ], we use the M A T L A B commands y k (t 0 ) = η k (21) >> F=@(t,y) [def of f 1 (t, y(1),, y(k)); ; def of f k (t, y(1),, y(k))]; >> [t y]=ode45(f, [t 0 t 1 ], [η 1 η 2 η k ]); where now, y is a k n matrix, whose j th row y(j) contains the (approximate) values of y j (t) If we want to plot the graphs of one (or more) of the (approximate) solutions, we use the command >> plot(t, y(:,j)) to plot y j 3 Examples Example 1 Use ode45 to plot (approximate) solutions of the system below on the interval [0, 5] y 1 ty 1 = y1 2 + y2 2 + 1 y 1 (0) = 1 y 2 = (y 2 y 1 ) 2 y 2 2 + y2 3 + 1 y 2 (0) = 0 (31) y 3 = t 2 y 2 3 y 2 1 + y2 3 + 1 y 3 (0) = 2 The M A T L A B commands >> F=@(t,y) [t*y(1)/(y(1) 2+y(2) 2+1); (y(2)-y(1)) 2/(y(2) 2+y(3) 2+1); t 2*y(3) 2/(y(1) 2+y(3) 2+1)]; >> [t y]=ode45(f,[0 2], [1 0-1]); >> plot(t, y(:,1), r, t, y(:,2), g, t, y(:,3), b ) 2

Figure 1: The output for Example 1 plot the graph of y 1 in red, the graph of y 2 in green and the graph of y 3 in blue, producing the plot in Figure 1 above Example 2 Suppose a pendulum has length l = 2 feet, and at time t = 0, it is displaced from its equilibrium position by the angle ϑ 0 = π/6 and released (with initial velocity 0) Plot the position (angle) of the pendulum as a function of time t, assuming that there is no damping, and determine the (approximate) period of the motion (ie, determine when the pendulum first returns to its initial position) We want to find the solution of the second order initial value problem ϑ + 1687 sin(ϑ) = 0, ϑ(0) = π 6, ϑ (0) = 0, where l = 2 (and g 32174) We can t solve this problem explicitly, so instead we will compute an approximate solution using ode45 To do this, we first need to transform the second order initial value problem into a pair of first order initial value problems ϑ + g l sin(ϑ) = 0, ϑ(0) = π ϑ 6, 1 = ϑ 2 ϑ 1 (0) = π 6 ϑ (0) = 0 = ϑ 2 = 1687 sin(ϑ 1 ) ϑ 2 (0) = 0 where ϑ 1 = ϑ and ϑ 2 = ϑ Next we use the M A T L A B commands See section 13 in the book for the derivation of the motion of an undamped pendulum 3

>> Pen=@(t,Theta) [Theta(2); -1687*sin(Theta(1))]; >> [t Theta]=ode45(Pen,[0 5],[pi/6 0]); >> plot(t,theta(:,1)) >> grid minor to produce the plot in Figure 2, below The last command grid minor, adds a fine grid to the plot which gives a better view of where the maxima are to determine the period Figure 2: Plot of the position of the pendulum in Example 2 From the plot, it appears that the pendulum first returns to its initial position about halfway between 15 and 16, ie, at about t p = 155 you can study the values stored in T(:,1) to find the index where π/6 05236 appears for the second time Then, with that index you can check the corresponding entry in the time vector t If you do this, you will find that the pendulum first returns to its initial position after about 15505 seconds 4 The phase plane, direction fields and phase portraits for 2x2 autonomous systems The solutions of the pair of first-order differential equations are distinguished by x = F(x) 4

[ ξ1 (t) Suppose that ξ(t) = ξ 2 (t) ] is a particular solution of the system then the graph whose points are {(ξ 1 (t), ξ 2 (t)) : a < t < b} is called the trajectory of this solution, and it is plotted in the phase-plane A phase-portrait for the system of equations consists of a collection of typical trajectories for the system (corresponding to different initial conditions) Plotting trajectories in M A T L A B is easy, and plotting a collection of trajectories to produce a phase portrait is just as easy Example 3 Consider the nonlinear system below } x 1 = 11x 1 03x 1 x 2 x 2 = 02x 1 x 2 05x 2 (41) Using ode45, we can produce different solutions to this (nonlinear) system (corresponding to different initial conditions) and then graph all the solutions in the same plot, as in Figure 3, below Figure 3: Phase portrait for the system (41) >> LV=@(t,X) [11*X(1)-03*X(1)*X(2); 02*X(1)*X(2)-05*X(2)]; >> [t X]=ode45(LV,[0 10],[7 2]); >> plot(x(:,1),x(:,2)); >> hold on >> [t X]=ode45(vdp,[0 10],[6 2]); >> plot(x(:,1),x(:,2)); etc Commands to produce Figure 3, above 5

Another common way to describe the possible solutions of a pair of autonomous first-order differential equations is to draw a direction field in the phase planeeach point in the phase-plane can be thought of as the initial point of a particular solution x(t) of the system x (t) = F(x) (42) In other words, if (ξ 1, ξ 2 ) is a point of the phase-plane, then there is a particular solution x(t) of the system 42 and a point t 0 such that [ ] [ ] ξ1 x1 (t = x(t 0 ) = 0 ) x 2 (t 0 ) ξ 2 To produce a direction field for the system (42), we choose and array of points in the phase plane, and then at each point (ξ 1, ξ 2 ) = ξ T in the array, we draw an arrow parallel to F(ξ) with its tail at (ξ 1, ξ 2 ) In M A T L A B, we can use the quiver command to do this, as illustrated below Example 4 Sketch a direction field for the system (41) in the first quadrant The sequence of M A T L A B commands below, produces the direction field in Figure 4 >> [x1 x2] = meshgrid(0:02:8,0:02:8); >> dx1=11*x1-03*x1*x2; >> dx2=02*x1*x2-05*x2; >> L=sqrt(dx1 2+dx2 2); >> quiver(x1,x2,dx1/l,dx2/l,06); axis tight Figure 4: Direction field for the system (41) 6

Example 5 Plot a direction field and three trajectories for the system [ ] [ ] [ ] d x 05 2 x = dt y 2 05 y Since we need some trajectories, we first find the general solution of the system: [ ] [ ] x = e t/2 c1 cos(2t) + c 2 sin(2t) y c 1 cos(2t) + c 2 sin(2t) Next, we plot three trajectories, starting at the initial points [ ] [ ] [ ] 2 1 2 ξ 1 =, ξ 15 2 = and ξ 3 3 = 25 The sequence of commands below produces the plot in Figure 5 >> t=[0:005:8]; >> x=exp(-t/2)*(2*cos(2*t)+15*sin(2*t)); >> y=exp(-t/2)*(-2*sin(2*t)+15*cos(2*t)); >> plot(x,y, r ); >> hold on >> x=exp(-t/2)*(1*cos(2*t)-3*sin(2*t)); >> y=exp(-t/2)*(-1*sin(2*t)-3*cos(2*t)); >> plot(x,y, g ); >> x=exp(-t/2)*(-2*cos(2*t)-25*sin(2*t)); >> y=exp(-t/2)*(2*sin(2*t)-25*cos(2*t)); >> plot(x,y, b ); >> grid on Since we want to plot the direction field in the same figure, we need to choose the limits of the meshgrid to be big enough to include the plot of the three trajectories Choosing 3 x 3 and 3 y 3, should work, and following the preview commands with >> [x y]=meshgrid(-3:025:3,-3:025:3); >> dx=-05*x+2*y; >> dy=-2*x-05*y; >> L=sqrt(x 2+y 2); >> quiver(x,y,dx/l,dy/l,05); axis tight yields the plot in Figure 6 Otherwise, there will be unattractive white space in the figure 7

Figure 5: Trajectories for Example 5 Figure 6: Trajectories and direction field for Example 5 8