### Create a StudySoup account

#### Be part of our community, it's free to join!

Already have a StudySoup account? Login here

# ENGR 232 DYNAMIC ENGINEERING SYSTEM ENGR 232

Drexel

GPA 3.55

### View Full Document

## About this Document

## 201

## 0

## Popular in Dynamic Engineering Systems

## Popular in Engineering and Tech

This 64 page Class Notes was uploaded by Haikal Fouzi on Thursday January 14, 2016. The Class Notes belongs to ENGR 232 at Drexel University taught by Mr. Michael Ryan in Spring 2015. Since its upload, it has received 201 views. For similar materials see Dynamic Engineering Systems in Engineering and Tech at Drexel University.

## Popular in Engineering and Tech

## Reviews for ENGR 232 DYNAMIC ENGINEERING SYSTEM

### What is Karma?

#### Karma is the currency of StudySoup.

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 01/14/16

ENGR 232 Dynamic Engineering Systems Lecture 1 Introduction to Numerical Solutions with Differential Equations Dr. Michael Ryan Perspective Solutions to 1 Order ODEs • Analytically - Separation of variables– quantitative • Explicit solution Implicit Solution • Qualitative analysis ▯▯ • Sketch ▯▯, find EQ. Plot trajectories about EP • Direction field –Graphical technique to sketch solution curve versus time, grid spacing • Numerical Solution of DE • Euler’s methodRunge-Kutta etc. • Analog Computer - future lab(Simulink) Read Chapter1 and 18 of Schaum’s Outline ENGR 232 Spring14-15 2 Introduction • Differential equations: Mathematical equations for an unknown function of one or several variables that relates the values of the function itself and its derivatives of various orders.dx ▯ at dt x ▯ 5x ▯ 6x ▯ u(t) ▯ ▯▯ = 0 1 ▯▯ + 0 ▯(▯) ▯▯ ▯▯ ▯2 ▯3 ▯▯ 1 (As opposed to algebraic equations▯▯▯+ ▯▯ + ▯ = ▯ ) • A differential equation that describes a physical process is often called a mathematical model • They play a prominent role in engineering, physics, economics, biology, and other disciplines. ENGR 232 Spring14-15 3 Population Growth; Mass-Spring Systems • Population growth (Malthus) dp ▯ rp dt d x dx • Mass-spring system subjected to force F m 2 ▯b ▯kx ▯ F(t) dt dt Lotka-Volterra Equations Prey Dynamics Predator Dynamics •x is the number of prey (for example, rabbits) •y is the number of some predator (for example, foxes) • and represent the growth rates of the two populations over time •t represents time •▯, ▯, ▯ and ▯ are parameters describing the interaction of the two species http://en.wikipedia.org/wiki/Lotka%E2%80%9 3Volterra_equation Cheetahs and Baboons • Initial conditions are 80 baboons and 40 cheetahs Examples and T erminology • Ordinary Differential Equation – one independent variable • Dependent and independent variables: – x is the dependent variable – t is the independent variable • Coefficients in the equation • a and k are coefficients of the equation. Partial Differential equation ▯▯+ ▯▯ = ▯ ▯ ▯▯ ▯▯ ▯▯ • x and y independent variables • u - dependent variable notation u(x,y) ENGR 232 Spring14-15 7 Order and Linearity • The order of an equation is the order of the highest-order derivative • Equation (1)is order 2 , equation (2) has is 1 . • Equations (1) and (2) are linear, because the dependent variables and their derivatives appear by themselves (no products or functions) • (3) is not linear because of y . • (4) is linear because dx/dt and x are not multiplied by functions of x. (note independent variable t is okay) • (5) Is not linear because of the y times dy/dx term. ENGR 232 Spring14-15 8 Order, Linear or Nonlinear ORDER Linear or Nonlinear (1) y▯▯ 3y ▯ 0 1 L y (2) y ▯▯3e y ▯ ▯t ▯ 0 2 NL (3) y ▯▯3y ▯ ▯t 2 ▯ 0 2 L d4 y d 2y (4) ▯ t ▯1▯ t 2 4 L dt4 dt2 2 NL (5) u xx▯ uu yysint 2 NL (6) u xx▯ sin(u)u ▯yyost ENGR 232 Spring14-15 9 Explicit Solution • A function ▯(▯) is an explicit solutionof a differential equation if it satisfies the equation over an interval of x values when ▯(▯) is substituted for y(x). ▯ ▯▯▯ ▯ ▯ =▯ ▯,▯, ▯▯ ,… ▯ ▯ ▯▯▯ ▯▯ ▯▯▯▯▯ Interval is important – we will see how to handle in examples ENGR 232 Spring14-15 10 Example Do the following functions satisfy the differential equation? ▯ ▯ ▯ • Consider derivatives ▯ ▯ = ▯ ▯ ▯ ▯▯ Substitute into D.E. ▯▯▯ ▯ ▯▯▯ = 0 ▯▯ = 2x + x▯▯ 2 ▯ 2▯▯▯ ▯ ▯(▯ ▯ ▯ ▯▯ ) = 0 ▯▯ ▯▯ ▯ ▯▯ ▯▯ ▯ ▯ = 2 ▯ 2x ▯▯ 2 ▯ 2▯ ▯ (2 ▯ ▯▯ ) = 0 ▯▯ ▯ Yes- satisfied • Function ▯ is valid for any x not equal to zero this it is an explicit solution on interval (-▯▯▯▯▯▯▯▯▯▯▯▯consider derivatives ENGR 232 Spring14-15 11 Example Do the following functions satisfy the differential equation? • Consider derivatives ▯ ▯ = ▯ ▯ Substitute into D.E.▯ ▯ ▯ ▯ ▯ = 0 ▯▯▯ ▯▯ ▯▯ ▯ ▯ = 3x ▯▯ ▯ ▯▯(▯ ) = 0 ▯▯ ▯ ▯ ▯ ▯▯ ▯ ▯▯ = ▯▯ = 0 ▯ = 6x ▯▯ Only satisfied if x = 0 Not on an interval • Function ▯ is not an explicit solution. ENGR 232 Spring14-15 12 Example • Show that the relation satisfies the following nonlinear equation (1) Solve the relation for y(x) = ▯(x) ▯ = ± ▯ ▯ 8 ▯ ▯ ▯ = ▯ ▯ 8 = ▯ ▯ 8 ▯ Choose + value for now ▯ ▯▯ = 3 ▯ ▯ 8 ▯▯▯▯ ▯▯ 2 (2)Substitute into the differential equation. 3 ▯▯ 3▯ ▯ ▯ ▯ 8 ▯▯ = ▯ LHS = RHS 2 2 ▯ ▯ 8 ▯ So it is a solution ENGR 232 Spring14-15 13 Example Where is it defined? Here we need to consider both ▯ ▯▯ 3 ▯ ▯ ▯ = ▯ ▯ 8 = ▯ ▯ 8 ▯ = ▯ ▯ 8 ▯▯▯▯ ▯▯ 2 For only positive or zero values in the square root (no complex roots)the argument ▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯ However the derivative has the square root in the denominator so it cannot equal zero ▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯ Students should verify the minus sign also works (try it) ENGR 232 Spring14-15 14 Example: Radioactive Decay Model • A(t) ::= amount of radioactive material • Disintegrations cause a decrease of the amount of material. • The number of disintegrations per second is proportional to the amount of material • Solving (separate variables, integrate both sides) ▯▯ ▯▯ ▯▯ = ▯▯ ▯▯ ▯ ▯ = ▯▯ ▯▯▯ ▯ ▯ = ▯▯ ▯ + ▯ ▯ • Integration yields two constants ▯▯ ▯ + ▯ = ▯kt + ▯ ENGR 232 Spring14-15 15 Radioactive Decay Model (cont.) • Since A(t) > 0 we can drop absolute value and combine both constants on the right ▯ = (▯2– ▯ 1 ln(A) = ▯kt + c • Solving for A ▯ = ▯ ▯▯▯▯▯ = ▯▯▯▯ ▯ ▯▯▯▯: ▯▯▯▯ = ▯ ▯ ▯ • But e is just another constant we can again call c (or anything else) • The result is: ▯ = ▯▯ ▯▯▯ • We find the value of c by knowing the initial condition Make sure you can do these manipulations with ln() and exponentials ENGR 232 Spring14-15 16 Initial Value Problem (IVP) • Recall the radioactive decay problem • Is this a solution? ▯ = ▯▯ ▯▯▯ ▯▯ ▯▯▯ ▯▯ = ▯kCe = ▯▯▯ • Good news: it satisfies equation - it is a solution • Feature:BUT it is not unique …. C is arbitrary • That means A = 35.78e -ktor A = 3ektor many other equations satisfy the D. E. • How do you pick the correct one? ENGR 232 Spring 14-15 17 Initial Value Problem - definition • By an initial value problem for an nth-order differential equation We mean: Find a solution to the differential equation on an interval I that satisfies the n initial conditions ▯ ▯▯ = ▯▯ ▯▯ ▯ = ▯ ▯ ▯ … ▯▯▯▯ ▯ ▯ = ▯ ▯▯▯ Where x ▯0▯▯▯▯▯▯▯▯ ▯0▯ 1▯▯ n-1▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯ Comment – for an n order differential equation you need n initial conditions starting at the dependent variable such as y ENGR 232 Spring14-15 18 Initial Value Example • General solution: ▯ ▯ = ▯▯ ▯▯▯ • Apply initial value ▯ 0 = 10 = ▯▯ ▯▯▯ 10 = ▯ • Specific solution: ▯ ▯ = 10▯ ▯▯▯ This is a unique solution! ENGR 232 Spring14-15 19 Implications Given a differential equation (of any order) and corresponding initial conditions To see if a given solution ▯(t) satisfies the IVP • Test if the solution has the corresponding initial conditions (differentiate and evaluate at t = 0) • If the IC’s don’t match it is not a solution of the IVP • If the IC’s match then you should substitute into D.E to make sure the solution satisfies the given D. E. ENGR 232 Spring14-15 20 Initial Value Problem Given: Find: y(x) over an interval that includes x 0 Typically a unique solution ENGR 232 Spring14-15 21 IVP: Example – General Solution ▯ ▯ ▯▯ ▯ ▯▯▯▯ ▯▯ ▯ ▯▯ = 0 ▯ 0 = 2 ▯ 0 = ▯3 Show that ▯ = ▯▯▯ ▯▯ + ▯▯▯ ▯▯ satisfies the differential equation (general solution). ▯ = ▯▯ ▯ ▯▯ + ▯▯ ▯ ▯▯ ▯ ▯ ▯▯ ▯▯ ▯▯ ▯ = ▯ ▯ ▯ + ▯▯ ▯ plug in ▯ ▯ ▯▯ + ▯▯ ▯ ▯▯ ▯ ▯▯ ▯▯ ▯▯ + ▯▯ ▯ ▯▯ ▯ 2 ▯ ▯ ▯▯ + ▯ ▯ ▯▯ = 0 The terms on LHS cancel so y is a solution regardless of values 1f c a2d c . This is a general solution – it is not unique We now need to find the solution to the IVP! ENGR 232 Spring14-15 22 IVP: Finding coefficients ▯ ▯ ▯ ▯▯ ▯ 0 = 2 ▯ 0 = ▯3 ▯▯ ▯▯ ▯▯ ▯ ▯▯ = 0 Substitute IC’s into solution and its derivative ▯ = ▯▯▯▯▯ + ▯▯▯▯▯ ▯ = ▯▯▯▯▯ + ▯▯▯▯ ▯ ▯▯ ▯▯ ▯▯ ▯ ▯ = ▯▯ ▯ + ▯▯▯▯ ▯3 = ▯▯ ▯ + ▯▯▯▯ Solve using Matrix techniques 7 1 1 ▯▯ 2 ▯▯ 3 ▯ = ▯▯ = 1 ▯1 2 ▯ ▯3 ▯ 3 IVP Solution: ▯ ▯ = ▯▯▯▯ ▯ ▯▯ ▯ ▯ How would ENGR 232 Spring14-15u check? 23 Example: Free Fall Problem • We drop a stone from the top of the CN Tower in Toronto (553m) How long before it hits the ground? Time impact How fast will it go? Terminas lpeed • General plot of what will happen (ignoring air friction) 0 600 400 -50 200 0 velocity m/s position m -100 -200 -400 -150 -600 0 5 time sec10 15 0 5 time sec10 15 • Plots do not stop at ground (i.e. h(t) = 0) ENGR 232 Spring14-15 24 Example: Free Fall model gravity only Formulate a differential equation describing motion of an object falling near sea level, neglect the force of the air. • Variables : time t, position h, velocity v • v = dh/dt, a = dv/dt = d h/dt2 • Newton’s 2 nd Law: F = ma = m(dv/dt) net force • Force of gravity: F = –mg downward force • At t = 0, h = H, v = 0. initial conditions • Plan: – Find equation for v(t); Find equation for h(t) – These are models for our system – they don’t take everything into account ENGR 232 Spring14-15 25 Example: Free Fall Model ▯ ▯ ▯ ▯ • Basic equation: F = ▯ ▯▯▯ = ▯▯▯ ▯ = ▯▯▯= ▯▯ • Simplify, integrate a to solve for dh/dt, the velocity ▯(▯) = ▯▯= ▯▯▯ + c ▯▯ ▯ • Apply initial condition, v(0) = 0 0 = ▯ 0 = ▯▯(0) + c c = 0 ▯ ▯ note we will carry c for generality 1 • Integrate again to get h(t). ▯▯ ▯ ▯ = ▯▯▯ ▯▯ = ▯ ▯▯ = ▯▯ ▯ ▯▯ =▯ ▯▯▯ + c ▯▯ ▯▯ ▯ ▯ ▯ ▯ = ▯ ▯▯ + c t + c h(0) implies c = H =553 ▯ ▯ ▯ 2 ENGR 232 Spring14-15 26 Example: Free Fall Model With our two equations and the initial conditions (c1 = 0 and c2 = 553 m) ▯(▯) = ▯▯▯ ▯ ▯ ▯ = ▯ ▯▯ + 553 2 We could easily solve for the time when h(t) = 0 t = 10.6234 sec and then use that time to determine the terminal velocity v(10.6234) = -104.12 These are the results of the model used. ENGR 232 Spring14-15 27 Increasing Model Complexity: A Falling Object from CN Tower • An object has mass m=0.025 kg and drag coefficient =0.007 kg/s.* • Taking g = 9.8 m/sec 2, the differential equation for the falling object is dv ▯ dv ▯ ▯ v m dt ▯ mg ▯▯v dt m Note that drag is in a direction opposite to gravitational force, 0.007 kg both signs could be reversed ▯ s ▯1 This model is sign reversed than ▯ ▯ 0.28s Lecture 1 free fall m 0.025kg ▯▯ *Values and equations ▯▯ = 9.8 - 0.28v froman example in Brannan and Boycetions by ENGR 232 Spring14-15 28 Manually Sketching Direction Field of falling object with drag Using differential equation make table, plot slopes (estimates) on axes below. (note values of v’ do not depend explicitly on t but solution v is a function of t, v(t)- this is easy case) Slope of v(t) ▯▯ v v' ▯▯ = 9.8 - 0.28v 0 9.8 5 8.4 10 7 15 5.6 20 4.2 25 2.8 30 1.4 35 0 Replicate slopes At each time step 40 -1.4 45 -2.8 50 -4.2 55 -5.6 60 -7 ENGR 232 Spring14-15 29 Direction Field & Equilibrium Solution for first order D.E. The arrows are tangent lines to solution curves, – Show where solution chosen is increasing/decreasing (and by how much). Horizontal solution curves are equilibrium solutions. – Value the solution curve approaches as time approaches infinity (constant value) – Solution curves may go to infinity – The equilibrium solutions can also be found analytically by setting the derivative to zero and solving for the critical points. – Not all critical points (aka equilibrium values) correspond to constant equilibrium solutions ENGR 232 Spring14-15 30 Computer Generated Direction Field for v’ = 9.8-0.28v http://math.rice.edu/~dfield/dfpp.html Qualitative solution via direction field Note that a falling object reaches a constant velocity when we include drag term Equilibrium solution v = 35 from plot and setting dv/dt = 0 ENGR 232 Spring14-15 31 Direction Fields – More general • Given: y’ = f(x, y) x is independent variable • Form an array of x, y values, plot line segments proportional to f(x, y) at the corresponding points. • Example: y’ = x – y2 • x = (-1, 0, 1), y = (-1, 0, 1). x y f -1 -1 2 -1 0 1 -1 1 0 0 -1 1 0 1 -1 Plot slopes at these points For case where slopes are not independent of time ENGR 232 Spring14-15 32 Direction Field -Rice Software ▯▯ • http://math.rice.edu/~dfield/dfpp.html = ▯ ▯ ▯ – Rice University direction field plotter ▯▯ – Matlab function (download) You can also hand sketch solution curves by starting at a point and following slopes Caution – Rice software Fills in solution curve in both the fwd and backward direction from the starting point (set option Slopes are NOT the same as you go across 33 Direction Field: Autonomous linear D.E. Critical point = 0, i.e. where derivative = 0 Y tends to 0 as x increases So we can get an indication of whether the solution goes to a constant final (equilibrium solution) value or grows without bound Approximation gets better if grid size is ENGR 232 Spring14-15 reduced 34 Direction Field: nonlinear ODE ▯▯ ▯▯ = ▯(▯ ▯ ▯) Critical points {0, 2} derivative set = 0 Look for equilibrium solutions For positive initial values, y tends to +2. For negative initial values y tends to negative infinity. We could also “estimate” the time it takes for curve starting at y = 1 to reach a value of 1.5. approximately “ 0.5 “ sec ENGR 232 Spring14-15 35 Direction Field- nonlinear D.E. 3 critical points ▯ 1 ▯ = ▯ 4 ▯(▯ + 4)(▯ ▯ 2) Initial condition IC = 0 stays at 0 IC>0 approach 2 IC<0 approach -4 Critical points { 0, 2, -4} The direction field provides qualatative/quantative information for 1 order ODE however what if we need a better solution ENGR 232 Spring14-15 36 Numerical Analysis • Useful when closed form analytic solutions cannot be found or are too complicated or difficult to find. • Introduce Euler’s method (pronounced Oiler’s) – Crude by modern standards (Matlab solvers) – Illustrates basic concepts – Exhibits errors in numerical approximation ENGR 232 Spring14-15 37 Euler’s Method • Solve IVP numerically ▯▯ = ▯ ▯,▯ = ▯ ▯ ▯ ▯ 0 = 1 ▯▯ • Choose an increment of 0.5 sec • Starting at ▯ ▯▯ ▯ = (0,1) find ▯ ,▯ ▯ – Compute slope = ▯ ▯▯,▯▯ = ▯ ▯ ▯ = 0 ▯ 1 = ▯1 – Follow along slope until you rea▯ = 0.5 – Determine value of ▯(0.5) = ▯▯+ ▯ ▯ ▯ ▯ ▯ ,▯ ▯ – Repeat process from ▯ ▯▯ ▯ = (0.5,0.5) ENGR 232 Spring14-15 38 Euler Solution Graphically Euler Method and Exact Solution ▯▯ 1.5 = ▯ ▯,▯ = ▯ ▯ ▯ ▯▯ ▯ ▯ = ▯ Solution • Start at ▯ ▯▯ ▯ = (▯,▯) slope = 1 ▯ ▯ ,▯ = ▯▯ ▯ ▯ • Follow along slope (red line) until you reach Seg 4 ▯ = ▯.▯ 0.5 y(t) exact and approximate Seg 1 • Determine value Slope evalueated ▯(▯.▯) = ▯ ▯ atinitial condition ▯ ▯ ▯ ▯ ▯ ,▯ ▯ ▯ ▯ 0 y(0.5)=1+(-1)0.5 = 0.5 0 0.5 1 1.5 2 2.5 3 time Think about direction field ENGR 232 Spring14-15 39 Compute Numerical Values via Excel ▯▯ Y = ▯ ▯,▯ = ▯ ▯ ▯ t Euler dydt ▯▯ ▯ ▯ = ▯ 0 1 -1 0.5 0.5 0 h 0.5 1 0.5 0.5 named variable 1.5 0.75 0.75 2 1.125 0.875 dydt(n) = t(n)-y(n) 2.5 1.5625 0.9375 y(n+1) = y(n)+h*dydt(n) ▯(▯.▯) = ▯ + ▯ ▯▯▯ ▯▯▯ ▯▯ y(0.5)=1+(-1)0.5 = 0.5 ENGR 232 Spring14-15 40 Compare Approximation to Analytical Solution ▯▯ = ▯ ▯,▯ = ▯ ▯ ▯ Y y ▯▯ t Euler dydt analytic error ▯ ▯ = ▯ ▯ ▯ = ▯ + ▯▯ ▯▯ ▯ ▯ 0 1 -1 1.000 0.000 0.5 0.5 0 0.713 0.213 h 0.5 1 0.5 0.5 0.736 0.236 named variable 1.5 0.75 0.75 0.946 0.196 2 1.125 0.875 1.271 0.146 dydt(n) = t(n)-y(n) 2.5 1.5625 0.9375 1.664 0.102 y(n+1) = y(n)+h*dydt(n) y(t) = t + 2*exp(-t) -1 ENGR 232 Spring14-15 41 Compare Approximation to Analytical Solution with smaller h = 0.25 t y Euler dydt y analytic error 0 1 -1 1.000 0.000 0.25 0.75 -0.5 0.808 0.058 Previous slide h = 0.5 0.5 0.625 -0.125 0.713 0.088 Shows an error of 0.213 0.75 0.59375 0.15625 0.695 0.101 Clearly smaller h makes approximation “better” 1 0.632813 0.367188 0.736 0.103 Error is now 0.088 1.25 0.724609 0.525391 0.823 0.098 Remember It is still an approximation ENGR 232 Spring14-15 42 Summary Euler’s Method Equations ▯▯ • Starting with IVP: = ▯ ▯,▯ ▯ ▯ = ▯ ▯ ▯▯ • Pick a value of h, the increment • Use equations ▯▯▯▯ = ▯ ▯ ▯ ▯▯▯▯ = ▯ ▯ ▯▯(▯ ,▯ )▯ • Iteratively compute ▯ ,▯ , ▯ ,▯ … ▯ ,▯ ▯ ▯ ▯ ▯ ▯ ▯ Where n = {0, 1, 2, ….. k} The piecewise-linear function corresponds to the approximation of y(t) for the IVP fo▯ ▯ ▯ ▯ ▯▯▯ ENGR 232 Spring14-15 43 Errors Roundoff Error • Chopping of numbers at each stage of computation • We may only carry 2 or 3 decimal places manually • Calculators and computers have limits in accuracy (nominally 8 or 16 places of accuracy) • Error accumulates significantly after many steps Discretization Error – From the process itself – basic approximation Linear approximation of tangent line and step size How to test if Roundoff Error a problem 1. Perform computations with given # of places of accuracy 2. Repeat with twice as many places 3. Compare results– if good agreement then roundoff is under control When do we worry? Using different platforms ENGR 232 Spring14-15 44 Runge-Kutta Methods • Euler uses information from the current pair (t , y ) tn n determine value at the next pair (t , y ) n+1 n+1 nd th • Runge-Kutta (2 and 4 order methods) use a look ahead to get the slopes at strategically chosen nearby points which are weighted to maximize the accuracy of the approximation. ENGR 232 Spring14-15 45 Second-order Runge-Kutta (aka midpoint method) • Use slope at (tn, n ) to look a half-step ahead to the point ▯ ▯ ▯▯+ ▯ , ▯▯ + ▯▯(▯▯,▯▯) • Compute slope at this midpoint and use this slope to move from (t , n )n to (t , y ) n+1 n+1 • The algorithm follows ENGR 232 Spring14-15 46 Second-order Runge-Kutta (aka midpoint method) Given the IVP ▯ = ▯ ▯,▯ ▯ ▯ = ▯ ▯ ▯ And a step size of h To go from▯ ▯▯ ▯ ▯▯ ▯▯▯▯,▯▯▯▯ ▯▯▯: ▯▯▯▯ = ▯▯+ ▯ ▯▯▯▯ = ▯▯+ ▯▯ ▯▯ where ▯▯▯ = ▯ ▯▯,▯▯ ▯ ▯ ▯▯▯ = ▯ ▯▯+ ,▯▯+ ▯▯▯ ▯ ▯ ENGR 232 Spring14-15 47 Numerical Example Consider Euler h = 0.5 step from t = 0.0 to 0.5 t y Euler dydt y analytic error 0 1 -1 1.000 0.000 0.5 0.5 0 0.713 0.213 ▯ ▯▯ = ▯ ▯ ▯▯ ▯ = ▯ ▯,▯ = (▯ ▯ ▯) = ▯▯ ▯ = ▯ ▯ + ▯ ,▯ + ▯ ▯ = ▯ ▯.▯▯,▯.▯▯ = ▯▯.▯ ▯▯ ▯ ▯ ▯ ▯ ▯▯ Using Runge-Kutta at t = 0.5, y = 0.75 Compare to Euler; ▯ ▯▯▯ = ▯▯+ ▯ = ▯.▯ RK error is -0.037 ▯▯▯▯ = ▯ ▯ ▯▯ ▯▯ = ▯ ▯ ▯.▯▯ = ▯.▯▯ ENGR 232 Spring14-15 48 Forth-order Runge-Kutta Given the IVP ▯ = ▯ ▯,▯ ▯ ▯ = ▯ ▯ ▯ And a step size of h; to go▯fr▯m▯▯ ▯▯▯▯,▯▯▯▯: ▯▯▯▯ = ▯▯+ ▯ ▯ ▯ ▯▯▯ = ▯▯+ ▯ ▯▯▯ + ▯▯ ▯▯ + ▯▯ ▯▯ + ▯▯▯ First computing ▯ ▯ ▯▯▯= ▯ ▯▯,▯▯ ▯▯▯= ▯ ▯ ▯ ▯ ,▯ + ▯▯▯▯ ▯ ▯ ▯ ▯▯▯ = ▯ ▯▯+ ,▯▯+ ▯▯▯ ▯▯▯= ▯ ▯ ▯ ,▯▯+ ▯▯ ▯▯ ▯ ▯ ▯ ENGR 232 Spring14-15 49 Error Comparison Solution of IVP ▯ = ▯ + ▯ ▯ 0 = 0 ▯ = 0.5 Method One step result Actual Error Exact y(1) = 0.1487… Euler y(1) = 0 0.1487… 2nd y(1) = 0.125 0.0237… Runge-Kutta th 4 y(1) = 0.15 0.0013… Runge-Kutta ENGR 232 Spring14-15 50 Numerical Solvers • Classification: – Fixed step methods • Euler, Runge-Kutta – Multistep methods – (uses previous steps) • Adams-Bashforth – Variable step size methods (adapt step sizes automatically) • Dormand-Prince • ODE45 - variable step Runge-Kutta method Matlab supports a variety of solvers ENGR 232 Spring14-15 51 Implementation of Euler Equation Using Matlab • Our implementation will use one of the elements needed by Matlab's differential equation solvers • Specifically writing y’= f(t,y) as a non-vectorized function which returns the derivative given for the pair (t,y). – Even if t is not explicitly used by the function it still must be present – The function can contain conditionals (if-then-else) – State space form for the D.E. This will become important when the order of the D.E > 1. ENGR 232 Spring14-15 52 Block Diagram of Implementation ENGR 232 Spring14-15 53 Implementing Euler Consider the IVP with h = 0.5 ▯ = ▯▯.▯▯ + ▯.▯ ▯ ▯ ▯ ▯ = ▯ 1) write the differential equation as a function m-file 2) use a for loop to implement the Euler algorithm. ENGR 232 Spring14-15 54 Function mfile function dydt = diffeq(t,y) dydt = -0.5*y + 1.5 - t; ▯ = ▯▯.▯▯ + ▯.▯ ▯ ▯ ▯ ▯ = ▯ IC is not included in function ENGR 232 Spring14-15 55 Script file Initialize Variables and Arrays %% ENGR 231: Euler_Exanple %% Initialize Variables dt = 0.5;% dt is the step size same as h in text yI = 1; % initial value y(0) tI = 0; % initial time tEnd = 5;% tEnd is the stop time %% Array Setup t = tI:dt:tEnd; % time vector starting at 0 % ending at tEnd, setps dt y = zeros(size(t)); % allocate storage for answer y(1) = yI; % first value in y; the initial condition . ENGR 232 Spring14-15 56 Algorithm Implementation Using For Loop %% Algorithm Implementation % k - Index of current y and t values % y(k) and t(k) - y and t values being computed % y(k-1) and t(k-1) - Values of y and t one % time step ago % yPrime - Differential evaluated at y and t for k = 2:length(y); % start at 2 since y(1) is IC yPrime = diffeq(t(k-1),y(k-1)); % compute derivative y(k) = y(k-1) + dt*yPrime; % Euler's Approximation end ENGR 232 Spring14-15 57 Plotting result %% Plot Solution plot(t,y, 'linewidth', 3) grid on title('ENGR 231: Euler Example') xlabel('Time'); ylabel('y(t)'); legend(['dt = ' num2str(dt)]) ENGR 232 Spring14-15 58 Final Plot Piecewise Linear Approximation 2 ENGR231: Euler Example dt = 0.5 1 0 y(t) Remember Matlab connected the Points by straight lines -2 -3 -4 0 1 2 3 4 5 Time ENGR 232 Spring14-15 59 Changing h (or dt) The following plot illustrates how the solution changes for different step values. • As the step size becomes smaller, the curve begins to converge to a specific shape. • It is important to realize that there are inaccuracies resulting from : the estimation properties of Euler’s Method and the step size! • All of these runs were done with the same Roundoff error • A smaller step size in Euler’s method improves the accuracy of the solution,. ENGR 232 Spring14-15 60 ENGR231: Euler Example- Varying dt 3 dt = 1.5 2 dt = 1 dt = 0.5 dt = 0.2 1 dt = 0.05 0 y(t) -1 -2 -3 -4 0 1 2 3 4 5 Time ENGR 232 Spring14-15 61 Summary and Moving Forward This Lecture • Dependent and independent variables • Order of differential equation • Linear or nonlinear equations (watch out for t in coefficients) • Solution of differential equation satisfied differential equation • Explicit solution • Interval of solution - check for problems (divide by 0, imaginary numbers, etc.) ENGR 232 Spring14-15 62 Summary and Moving Forward This Lecture • Direction fields – qualitative solution – lead in to Euler • Numerical solution of ODE using fixed step solver – Euler and Runge-Kutta • Use Rice software to get direction field • Implementation of Euler via Matlab – Function to find derivative – similar to using solvers in Matlab – Look at changing step size ENGR 232 Spring14-15 63 Summary and Moving Forward Next Lecture • Define some metrics to compare numerical solution to exact solution. • Use Matlab’s ODE45 solver (Runge-Kutta 4 with variable step) to solve some of our system problems. • Address implicit solutions ENGR 232 Spring14-15 64

### BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.

### You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the material...plus I made $280 on my first study guide!"

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.