Chapter 7. Solution of Ordinary Differential Equations

Similar documents
UNIT 2 SOLUTION OF ALGEBRAIC AND TRANSCENDENTAL EQUATIONS

( ) 2 2. Multi-Layer Refraction Problem Rafael Espericueta, Bakersfield College, November, 2006

PGE 310: Formulation and Solution in Geosystems Engineering. Dr. Balhoff. Interpolation

Functions of Random Variables

Derivation of 3-Point Block Method Formula for Solving First Order Stiff Ordinary Differential Equations

2006 Jamie Trahan, Autar Kaw, Kevin Martin University of South Florida United States of America

Laboratory I.10 It All Adds Up

Fourth Order Four-Stage Diagonally Implicit Runge-Kutta Method for Linear Ordinary Differential Equations ABSTRACT INTRODUCTION

7.0 Equality Contraints: Lagrange Multipliers

1 0, x? x x. 1 Root finding. 1.1 Introduction. Solve[x^2-1 0,x] {{x -1},{x 1}} Plot[x^2-1,{x,-2,2}] 3

Beam Warming Second-Order Upwind Method

Supervised learning: Linear regression Logistic regression

MOLECULAR VIBRATIONS

1 Onto functions and bijections Applications to Counting

CHAPTER 4 RADICAL EXPRESSIONS

We have already referred to a certain reaction, which takes place at high temperature after rich combustion.

0/1 INTEGER PROGRAMMING AND SEMIDEFINTE PROGRAMMING

Numerical Solutions of Second Order Initial Value Problems of Bratu-Type equation Using Higher Ordered Rungu-Kutta Method

Lecture 07: Poles and Zeros

Chapter 9 Jordan Block Matrices

Econometric Methods. Review of Estimation

Multiple Choice Test. Chapter Adequacy of Models for Regression

Applied Fitting Theory VII. Building Virtual Particles

Third handout: On the Gini Index

CS 1675 Introduction to Machine Learning Lecture 12 Support vector machines

G S Power Flow Solution

Lecture Notes 2. The ability to manipulate matrices is critical in economics.

Lecture 12 APPROXIMATION OF FIRST ORDER DERIVATIVES

Part 4b Asymptotic Results for MRR2 using PRESS. Recall that the PRESS statistic is a special type of cross validation procedure (see Allen (1971))

Chapter 5. Curve fitting

Maximum Likelihood Estimation

Chapter 5 Properties of a Random Sample

Evaluating Polynomials

( ) = ( ) ( ) Chapter 13 Asymptotic Theory and Stochastic Regressors. Stochastic regressors model

2/20/2013. Topics. Power Flow Part 1 Text: Power Transmission. Power Transmission. Power Transmission. Power Transmission

Solving Constrained Flow-Shop Scheduling. Problems with Three Machines

Investigating Cellular Automata

Lecture 7. Confidence Intervals and Hypothesis Tests in the Simple CLR Model

Algorithms behind the Correlation Setting Window

Comparison of Dual to Ratio-Cum-Product Estimators of Population Mean

For combinatorial problems we might need to generate all permutations, combinations, or subsets of a set.

5 Short Proofs of Simplified Stirling s Approximation

DKA method for single variable holomorphic functions

Regression and the LMS Algorithm

Binary classification: Support Vector Machines

Given a table of data poins of an unknown or complicated function f : we want to find a (simpler) function p s.t. px (

Mechanics of Materials CIVL 3322 / MECH 3322

EECE 301 Signals & Systems

Ideal multigrades with trigonometric coefficients

Simple Linear Regression

Chapter 2 Supplemental Text Material

Lecture 5: Interpolation. Polynomial interpolation Rational approximation

MMJ 1113 FINITE ELEMENT METHOD Introduction to PART I

STK4011 and STK9011 Autumn 2016

1. A real number x is represented approximately by , and we are told that the relative error is 0.1 %. What is x? Note: There are two answers.

Numerical Analysis Formulae Booklet

Support vector machines II

Johns Hopkins University Department of Biostatistics Math Review for Introductory Courses

Analysis of Lagrange Interpolation Formula

Homework Assignment Number Eight Solutions

Correlation and Regression Analysis

Lecture 1: Introduction to Regression

Johns Hopkins University Department of Biostatistics Math Review for Introductory Courses

Cubic Nonpolynomial Spline Approach to the Solution of a Second Order Two-Point Boundary Value Problem

Investigation of Partially Conditional RP Model with Response Error. Ed Stanek

hp calculators HP 30S Statistics Averages and Standard Deviations Average and Standard Deviation Practice Finding Averages and Standard Deviations

ENGI 4430 Numerical Integration Page 5-01

Logistic regression (continued)

{ }{ ( )} (, ) = ( ) ( ) ( ) Chapter 14 Exercises in Sampling Theory. Exercise 1 (Simple random sampling): Solution:

Lecture Notes Forecasting the process of estimating or predicting unknown situations

PHYS Look over. examples 2, 3, 4, 6, 7, 8,9, 10 and 11. How To Make Physics Pay PHYS Look over. Examples: 1, 4, 5, 6, 7, 8, 9, 10,

d dt d d dt dt Also recall that by Taylor series, / 2 (enables use of sin instead of cos-see p.27 of A&F) dsin

Objectives of Multiple Regression

Summary of the lecture in Biostatistics

On Modified Interval Symmetric Single-Step Procedure ISS2-5D for the Simultaneous Inclusion of Polynomial Zeros

L5 Polynomial / Spline Curves

ESS Line Fitting

Overview of the weighting constants and the points where we evaluate the function for The Gaussian quadrature Project two

Chapter 4 (Part 1): Non-Parametric Classification (Sections ) Pattern Classification 4.3) Announcements

Ordinary Least Squares Regression. Simple Regression. Algebra and Assumptions.

ECONOMETRIC THEORY. MODULE VIII Lecture - 26 Heteroskedasticity

Introduction to local (nonparametric) density estimation. methods

Descriptive Statistics

F. Inequalities. HKAL Pure Mathematics. 進佳數學團隊 Dr. Herbert Lam 林康榮博士. [Solution] Example Basic properties

å 1 13 Practice Final Examination Solutions - = CS109 Dec 5, 2018

ENGI 4421 Propagation of Error Page 8-01

Can we take the Mysticism Out of the Pearson Coefficient of Linear Correlation?

Power Flow S + Buses with either or both Generator Load S G1 S G2 S G3 S D3 S D1 S D4 S D5. S Dk. Injection S G1

2SLS Estimates ECON In this case, begin with the assumption that E[ i

Initial-Value Problems for ODEs. numerical errors (round-off and truncation errors) Consider a perturbed system: dz dt

best estimate (mean) for X uncertainty or error in the measurement (systematic, random or statistical) best

Multiple Regression. More than 2 variables! Grade on Final. Multiple Regression 11/21/2012. Exam 2 Grades. Exam 2 Re-grades

Discrete Mathematics and Probability Theory Fall 2016 Seshia and Walrand DIS 10b

Ahmed Elgamal. MDOF Systems & Modal Analysis

Lecture 3 Probability review (cont d)

X ε ) = 0, or equivalently, lim

Stability For a stable numerical scheme, the errors in the initial condition will not grow unboundedly with time.

Mean is only appropriate for interval or ratio scales, not ordinal or nominal.

1 Lyapunov Stability Theory

Lecture 1: Introduction to Regression

Transcription:

Ordar Dfferetal Equatos - 4 Chapter 7. Soluto of Ordar Dfferetal Equatos 7.. Itroducto The damc behavor of ma relevat sstems ad materals ca be descrbed wth ordar dfferetal equatos ODEs. I ths chapter, we provde a troducto to the techques for umercal soluto of ODEs. We beg wth a sgle, frst-order ODE tal value problem. We the et the process to hgh-order ODEs, sstems of ODEs ad boudar value problems. The techques descrbed ths chapter work for both lear ad olear ODEs. However, we pot out that for lear ODEs ad some o-lear ODEs there ma est more elegat aaltcal solutos. I ths book, we do ot vestgate the aaltcal solutos but lmt ourselves to umercal methods that provde vald solutos. 7.. Ital Value Problems Regardless of whether oe ts to solve a ordar dfferetal equato ODE wth aaltcal or umercal techques, the problem must frst be properl posed. Let us tall lmt ourselves to a sgle, frst-order ODE, volvg a sgle depet varable ad a sgle depet varable. Dfferetal equatos that volve more tha oe depet varable are called partal dfferetal equatos PDEs ad are ot cosdered ths book. Dfferetal equatos that volve more tha oe depet varable costtute sstems of ODEs ad addressed later ths chapter. The soluto to a ODE s a fucto,. The most geeral formulato of ths ODE s f,, 7. where we have voked the shorthad otato, d d, for the dervatve of wth respect to. Ofte, t s possble through algebrac mapulato of equato 7. to solate the dervatve o the LHS, f, 7.

Ordar Dfferetal Equatos - 5 Ths s perhaps the most famlar form of a ODE, but t s ot the most geeral. ODEs are frequetl categorzed as lear ad olear ODEs. It s mportat to remember that the leart of the ODE s defed b the leart of ol ad specfcall ot of. The ukow must be operated o eclusvel b lear operators order for the ODE to be cosdered lear. Recall that the dfferetal operator s a lear operator. The geeral form of a lear frst order ODE s a b c 7.3 The coeffcets, a, b ad c ca be olear fuctos of. Regardless of whether oe s solvg a ODE of the form gve 7., 7. or 7.3, the problem s ot properl posed ad does ot have a uque soluto utl a tal codto s suppled. The tal codto provdes a value of the fucto at oe pot. 7.4 The tal value problem IVP s the combato of the ODE ad the tal codto. 7.3. Euler Method It s structve to beg our stud of umercal techques for solvg ODEs wth a frst order method. I practce, we wll ever use a frst-order method to solve a ODE, due to ts low accurac. Nevertheless, the frst-order method plas a mportat role as a structoal tool. The Euler method reles o a Talor seres trucated after the lear term. f df f h O h 3. d whch ca be rewrtte the omeclature of ODEs as 7.5 where the dscretzato s gve b. Equato 7.5 s the Euler method. Oe begs at the tal codto,, as gve the problem statemet. Oe choose a dscretzato,, whch s a crucal decso. Oe the evaluates the dervatve at usg the ODE equato 7., 7. or 7.3, whch also was gve the problem statemet. The Euler method equato 7.5 ca the be used drectl to estmate the value of the ukow fucto at

Ordar Dfferetal Equatos - 6. Ths process ca be repeated movg further dow the -as for as log as terest remas. Before we troduce specfc eamples, two pots of dscusso are ecessar. Frst, the choce of dscretzato or step-sze s crucal. It s true that the smaller the step-sze the more accurate the soluto. However, we must balace the desre for accurac wth the eed for computatoal effcec. If our choce of step-sze s so small that we eed a tractable umber of steps, the that does t help us. If the step sze s too bg, the method wll fal. I fact, for the smple methods preseted ths book, the ol reaso a umercal route for solvg a ODE wll fal s because the step-sze was too large. The reaso ca be see Fgure 7.. I the top fgure, t s clear that as the step-sze creases, the error creases. The error s quatfed the mddle fgure. For some fuctos t s possble that the error leads to values of the fucto that are ot permtted, such as egatve values of fuctos that requre a square root. The secod pot of terest s the determato of whe to stop the Euler teratos. The fal value of s smpl chose b the user. Frequetl, the stoppg pot s determed whe oe has reached a stead state. For eample the bottom part of Fgure 7., the fucto clearl goes to zero. Cotug to solve the ODE out to large values of tpcall serves o useful purpose. If oe does t kow how log t wll take to reach a stead state, the oe ma have to guess the fal value. If t s too short, the oe ca smpl et the Euler procedure usg the fal pot of the prevous process as the tal codto for the f relatve error f..8.6.4..35.5.5.5 aaltcal soluto Euler d =. Euler d=. Euler d =.5 tal codto...3.4.5.6.7.8.9.4.3.. Euler d =. Euler d=. Euler d =.5...3.4.5.6.7.8.9..8.6.4. aaltcal soluto Euler d =. tal codto 4 6 8 4 6 8 Fgure 7. Applcato of Euler method to =- wth tal codto ==. Top: soluto up to =. Mddle: error up to =. Bottom: soluto up to =.

Ordar Dfferetal Equatos - 7 cotuato. A MATLAB code whch mplemets the Euler method for a sgle frst-order ODE s provded later ths chapter. 7.4. Classcal Fourth-Order Ruge-Kutta Method The obvous soluto to accurac of the Euler method s to crease the order of the method. There are umerous flavors of ODE solvers of all orders. Here we smpl preset the Classcal Fourth-Order Ruge-Kutta RK4 Method, whch s a tred ad true soluto techque. The RK4 method proceeds as does the Euler method b startg at the tal codto ad followg a estmate of the average slope over the terval,, out to the et dscretzato pot. 7.6 I the Euler method, the estmate of the average slope was, smpl the value of the slope at the begg of the terval. The RK4 method uses a hgher order appromato for the average slope over the terval, amel where k k k3 k4 7.7 6 k k k k 3 4 ' ' ' ',, k, k, k 3 7.8 Wthout a rgorous dervato, we ca see that the Ruge-Kutta method mproves the qualt of the estmate of the slope over the terval b evaluatg the slope at the begg, mddle twce ad of the terval. The RK4 method s a fourth-order method, so the error decreases as the stepsze to the fourth power. I Fgure 7., we preset a applcato of the RK4 method. I the left fgure we show that eve for coarse dscretzato, the RK4 method ca be ver accurate. I the rght fgure we quatf the relatve error. Note that the error s ow show o a log as

Ordar Dfferetal Equatos - 8.E+..E- aaltcal soluto RK4 d =. RK4 d=.5.e- Euler d =. tal codto relatve error f.8.6.e-3 RK4 d =..E-4 RK4 d=.5 Euler d =..E-5.4.E-6..E-7.E-8...3.4.5.6.7.8.9..4.6.8 Fgure 7.. Applcato of RK4 method to =- wth tal codto ==. Left: soluto up to =. Rght: error up to =. A MATLAB code whch mplemets the classcal fourth-order Ruge-Kutta method for a sgle frst-order ODE s provded later ths chapter. 7.5. Applcato to Sstems of Ordar Dfferetal Equatos The eteso of the Euler or Ruge-Kutta method to sstems of ODEs s ver straghtforward for a tal value problem. Let s suppose that we have ODEs, each of whch ca be wrtte the form of equato 7. as d f,,, 3,..., d d f,,, 3,..., d... d f,,, 3,..., d 7.9 wth tal codtos:, for to 7. The fact that all of the codtos are gve at the same value of s what makes ths problem a IVP. Note carefull, that there are ODE s, thus fuctos, f, ad ukow fuctos,,

Ordar Dfferetal Equatos - 9 but there s ol oe depet varable. Ths s what makes ths sstem a sstem of ODEs rather tha PDEs. The techques ths chapter wll ot solve PDEs. The Euler method for a sstem of of ODEs ca be wrtte as 3 * f,,,,..., for = to 7. There s o dfferece betwee ths equato ad the equato for the sgle sstem ODE usg Euler s method equato 7.5. I ths case, remember that the subscrpt attached to the ad the f deotes dfferet fuctos. The subscrpt attached to the varable deotes steps or teratos. The Euler algorthm for a sstem of ODEs smpl requres oe to evaluate all f at terato from the ODEs the problem statemet equato 7.9, the compute all at terato + from equato 7. ad repeat the process. The eteso of RK4 to sstems of ODE s s ust as smple as the eteso of Euler s method. However, because RK4 has a lttle more sophstcato, the eteso looks more complcated, whe t s reall ot. The RK4 equato for a sstem of equatos s gve b 6 k k k k h,, 3, 4, for = to 7. where k k k k,, 3, 4, f, m f, m k m 3, m, m f, m k f, k, m for = to 7.3 I equato 7.3, the braces m represet the set of all m from m = to., all of whch are evaluated at. The mult-ode RK4 algorthm requres that oe frst evaluate all k,. Wth k, had, oe ca compute the argumets requred for k,. Oce all of the k, are kow, oe ca et compute the argumets requred for k 3,. Oce all of the k 3, are kow, oe ca et compute the argumets requred for k 4,. Oce all the k,, k,, k 3, ad k 4, are kow, oe ca use the RK4. method equato 7. to evaluate the value of the ukow fuctos at the et step, MATLAB codes whch mplemet the Euler method ad the classcal fourth-order Ruge- Kutta method for a sstem of frst-order ODEs are provded later ths chapter.

Ordar Dfferetal Equatos - 7.6. Hgher-Order ODEs Regardless of whether oe s pursug a aaltcal or umercal soluto to a hgher tha frst order ODE, there s a smple trck to covertg a th -order ODE to a sstem of frst-order ODEs. You make a substtuto that trasforms the th-order dfferetal equato to frstorder dfferetal equatos. Cosder a th -order ODE of the form,,, d d d d d d f d d 7.4 wth the followg tal codtos:,,, d d d d d d 7.5 The coverso s a three step process. The frst step s defg ew varables, whch alwas have the followg form: 3 d d d d d d 7.6 The secod step s wrtg oe frst-order ODE for each of these varables. The frst - ODEs have a trval form. The last ODE s smpl the orgal hgher-order ODE, equato 7.4, wth the ew varables, equato 7.6 substtuted.

Ordar Dfferetal Equatos - d d d 3 d 7.6 d d d f,, d, 3 The thrd ad fal step of the coverso process s to rewrte the tal codtos, equato 7.5, terms of the ew varables, 7.7,, 3, After the coverso equatos 7.6 ad 7.7 have costtute a sstem of frst-order ODEs wth tal codtos. Ths IVP ca be solved usg the methods of the prevous secto. 7.7. Boudar Value Problems Whe oe vokes Fck s law of dffuso a materal balace, or Fourer s law of heat coducto a eerg balace, or Newto s law of vscost a mometum balace, oe ca up wth a stead-state model that s a secod order ODE, where the depet varable s posto. What dstgushes these problems from other hgher-order ODEs s that the codtos are ot gve at the same pot. From a mathematcal pot of vew, we ca wrte ths equato as d d f,, d d 7.8 wth the followg boudar codtos: ad f f 7.9 Istead of beg gve the value of the fucto ad ts dervatve at a sgle pot,, we ow have a costrat o the fucto at two pots, ad f. For eample, we kow the temperature at ether sde of a metal rod,where our thermocouples are attached, but we kow othg about the

Ordar Dfferetal Equatos - dervatve of the temperature. The boudar codtos equato 7.9 defe what s called the Boudar Value Problem BVP. As preseted, the Euler or RK4 ol work for IVPs, ot BVPs. The soluto les creatg a umercal method that combes our ablt to umercall solve olear algebrac equatos d wth ODEs. If we had bee gve a tal value of the frst dervatve,, we d would have a IVP ad we could solve the problem easl, usg the techques Secto 7.6 breakg up the secod-order ODE to two frst-order ODEs ad Secto 7.5 solvg a sstem of frst-order ODEs a IVP. Therefore, we pla to our stregths. We wll guess a value of. We wll solve the sstem of ODEs from to f. We wll compare the calculated value of f wth the boudar codto, f. If the match wth a tolerace, we made a good guess. Probabl, the do t match ad we must make a ew guess for ad terate aga. What should gude our guess for? Wh, I have a ust the thg! We should use the Newto-Raphso method wth umercal dervatves for solvg a sgle olear algebrac equato. The ukow s. The algebrac equato s f g 7. f I other words, we must choose the correct tal codto o the dervatve to satsf the gve boudar codto o the fucto. We uderstad that sce f s arrved at va the soluto of the set of ODEs, that chagg the value of wll chage the value of f. Ever evaluato of the fucto gve equato 7. requres a soluto of the sstem of ODEs. A MATLAB code whch mplemets the soluto of a BVP for a sstem of ODEs usg the Newto-Raphso method ad the classcal fourth-order Ruge-Kutta method s provded later ths chapter. 7.8. Subroute Codes I ths secto, we provde routes for mplemetg the varous umercal ODE solver methods descrbed above. Note that these codes correspod to the theor ad otato eactl as lad out ths book. These codes do ot cota etesve error checkg, whch would complcate the codg ad defeat ther purpose as learg tools. That sad, these codes work ad ca be used to solve problems. As before, o the course webste, two etrel equvalet versos of ths code are provded ad are ttled code.m ad code_short.m. The short verso s preseted here. The loger verso, cotag structos ad servg more as a learg tool, s ot preseted here. The umercal mechacs of the two versos of the code are detcal.

Ordar Dfferetal Equatos - 3 Code 7.. Euler Method ODE euler_short fucto [,]=euler_short,o,f,o; d = f-o/; = zeros+,; for = ::+ = o + -*d; = zeros+,; = o; for = :: dd = fukeval,; + = + d*dd; close all; plot = ; f plot == plot,,'k-o', label '', label '' ; fd = fope'euler_out.tt','w'; fprtffd,' \'; fprtffd,'%3.5e %3.5e \', [,]'; fclosefd; fucto dd = fukeval,; dd = -.*; A eample of usg euler_short s gve below.» [,]=euler_short,,,; Ths program geerates outputs three forms. Frst, the ad vectors are stored memor ad ca be drectl accessed. Secod, the program geerates a plot of vs.. Thrd, the program geerates a output fle, euler_out.tt, that cotas ad vectors tabulated form. Code 7.. Fourth-Order Ruge-Kutta Method ODE rk4_short fucto [,]=rk4_short,o,f,o; d = f-o/; = zeros+,; for = ::+ = o + -*d; = zeros+,; = o; for = :: = ; = ; k = fukeval,; = +.5*d;

= +.5*d*k; k = fukeval,; 3 = +.5*d; 3 = +.5*d*k; k3 = fukeval3,3; 4 = + d; 4 = + d*k3; k4 = fukeval4,4; dd =./6.*k +.*k +.*k3 + k4; + = + d*dd; close all; plot = ; f plot == plot,,'k-o', label '', label '' ; fd = fope'rk4_out.tt','w'; fprtffd,' \'; fprtffd,'%3.5e %3.5e \', [,]'; fclosefd; fucto dd = fukeval,; dd = -.* A eample of usg rk4_short s gve below.» [,]=rk4_short,,,; Ordar Dfferetal Equatos - 4 Ths commad geerates outputs three forms. Frst, the ad vectors are stored memor ad ca be drectl accessed. Secod, the program geerates a plot of vs.. Thrd, the program geerates a output fle, rk4_out.tt, that cotas ad vectors tabulated form. Code 7.3. Euler Method ODEs euler_short fucto [,]=euler,o,f,o; d = f-o/; = zeros+,; for = ::+ = o + -*d; m=maszeo; = zeros+,m;,:m = o:m; dd = zerosm,; for = :: dd = fukeval,,:m; +,:m =,:m + d*dd:m; close all; plot = ; f plot ==

Ordar Dfferetal Equatos - 5 for = ::m color_de = get_plot_color; plot :,:,,color_de; hold o; hold off; label '' ; label '' ; leg tstr[:m]'; fd = fope'euler_out.tt','w'; fprtffd,'... m \'; for = ::+ fprtffd,'%3.5e ', ; for = ::m fprtffd,'%3.5e ',,; fprtffd,' \'; fclosefd; fucto dd = fukeval,; dd = -.* -.* -.5*3; dd = -.* - 4.* -.5*3; dd3 = -.5* -.4* -.*3; A eample of usg euler_short s gve below.» [,]=euler,,,[,,]; Note that the fourth put argumet, o, s ow a vector. Ths program geerates outputs three forms. Frst, the vector ad matr are stored memor ad ca be drectl accessed. Secod, the program geerates a plot of vs.. Thrd, the program geerates a output fle, euler_out.tt, that cotas ad tabulated form. Also ote that ths code calls a acllar fucto for plottg, get_plot_color, whch s reproduced below. The fucto assgs a dfferet color to each fucto so that the curves are dstgushable o the graph. Ths fucto ca be cluded at the bottom of the fle euler_short.m. fucto color_de = get_plot_color; f == color_de = 'k-'; elsef == color_de = 'r-'; elsef == 3 color_de = 'b-'; elsef == 4 color_de = 'g-'; elsef == 5

Ordar Dfferetal Equatos - 6 color_de = 'm-'; elsef == 6 color_de = 'k:'; elsef == 7 color_de = 'r:'; elsef == 8 color_de = 'b:'; elsef == 9 color_de = 'g:'; elsef == color_de = 'm:'; else color_de = 'k-'; Code 7.4. Classcal Fourth-Order Ruge-Kutta Method ODEs rk4_short fucto [,]=rk4_short,o,f,o; d = f-o/; = zeros+,; for = ::+ = o + -*d; m=maszeo; = zeros+,m;,:m = o:m; dd = zeros,m; temp = zeros,m; k = zeros,m; k = zeros,m; k3 = zeros,m; k4 = zeros,m; for = :: = ; temp:m =,:m; k:m = fukeval,temp; = +.5*d; temp:m =,:m +.5*d*k:m; k:m = fukeval,temp; 3 = +.5*d; temp:m =,:m +.5*d*k:m; k3:m = fukeval3,temp; 4 = + d; temp:m =,:m + d*k3:m; k4:m = fukeval4,temp; dd:m =./6.*k:m +.*k:m +.*k3:m + k4:m; +,:m =,:m + d*dd:m; close all; plot = ; f plot == for = ::m

Ordar Dfferetal Equatos - 7 color_de = get_plot_color; plot :,:,,color_de; hold o; hold off; label '' ; label '' ; leg tstr[:m]'; fd = fope'rk4_out.tt','w'; fprtffd,'... m \'; for = ::+ fprtffd,'%3.5e ', ; for = ::m fprtffd,'%3.5e ',,; fprtffd,' \'; fclosefd; fucto dd = fukeval,; dd = -.* -.* -.5*3; dd = -.* - 4.* -.5*3; dd3 = -.5* -.4* -.*3; A eample of usg rk4_short s gve below.» [,]=rk4,,,[,,]; Note that the fourth put argumet, o, s ow a vector. Ths program geerates outputs three forms. Frst, the vector ad matr are stored memor ad ca be drectl accessed. Secod, the program geerates a plot of vs.. Thrd, the program geerates a output fle, euler_out.tt, that cotas ad tabulated form. Also ote that ths code calls a acllar fucto for plottg, get_plot_color, whch s reproduced above. The fucto assgs a dfferet color to each fucto so that the curves are dstgushable o the graph. Ths fucto ca be cluded at the bottom of the fle rk4_short.m. Code 7.5. Newto-Raphso/Ruge-Kutta Method ODEs BVP rd & rk4 No ew codes were used to solve the BVP problem. Istead the put fles for the Newto- Raphso wth umercal dervatves rd.m ad the classcal fourth-order Ruge-Kutta method for a sstem of ODEs rk4.m were modfed. I the fle rk4.m, we etered the ODEs fucto dd = fukeval,; dd = ; dd = -.* -.5*;

Ordar Dfferetal Equatos - 8 I the fle rd.m, the put fucto was specfed as fucto f = fukeval o = ; o_ = ; o_ = ; f =.; f =.; = ; [,]=rk4,o,f,[o_,o_]; f_calc = +,; f = f_calc-f; I ths put fle, we call the Ruge-Kutta route. We provde the gve boudar codtos. We allow the tal codto for the secod fucto to var wth each terato, sce t s the ukow the Newto-Raphso procedure. A eample of usg solvg ths BVP s gve below.» [,err] = rd. cout = old =.e- f = -.45e+ df = 5.85e- ew =.836e+ err =.e+ cout = old =.836e+ f = -.6755e-3 df = 5.85e- ew =.836e+ err =.374e-3 =.83 err =.37e-3 The problem was solved oe terato because the ODEs were lear. It took a secod terato to detf covergece. The tal value of the dervatve requred to solve the boudar codto s.83. The rk4.m program geerates a plot of vs. ad geerates a output fle, rk4_out.tt, that cotas ad tabulated form. However, be wared that ths plot ad table of data correspod to the last call of the Ruge-Kutta route b the Newto-Raphso code, whch would have bee to evaluate the umercal dervatve. Therefore, ths plot does ot correspod eactl to the soluto. To geerate the soluto, ru the Ruge-Kutta code wth the approprate tal codto.» [,]=rk4,,,[,.83]; The resultg plot s show Fgure 7.3. It demostrates that the fal value of s deed the specfed value of.

Ordar Dfferetal Equatos - 9.5 7.9. Problems Problems are located o course webste..5 -.5 - -.5..4.6.8..4.6.8 Fgure 7.3. Soluto to boudar value problem. d d subect to the d d boudar codtos ad. The two curves correspod to black ad the frst dervatve red.