MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.

Slides:



Advertisements
Similar presentations
Boyce/DiPrima 9th ed, Ch 2.4: Differences Between Linear and Nonlinear Equations Elementary Differential Equations and Boundary Value Problems, 9th edition,
Advertisements

ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Partial Differential Equations
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Laplace Transform Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2008 by Douglas Wilhelm Harder.
Differentiation and Richardson Extrapolation
Topics in Applied Mathematics Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Part 6 Chapter 22 Boundary-Value Problems PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill.
Boundary-value Problems and Finite-difference Equations Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Differential Equations and Boundary Value Problems
Heat-conduction/Diffusion Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
The Shooting Method for Boundary-value Problems
Scientific Computing Partial Differential Equations Introduction and
Fixed-Point Iteration Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007 by Douglas Wilhelm.
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Welcome to ECE 204 Numerical Methods for Computer Engineers Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo.
Proof by Induction.
The Crank-Nicolson Method and Insulated Boundaries
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Binary Numbers Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007 by Douglas Wilhelm Harder.
Copyleft  2005 by Media Lab Ordinary Differential Equations Boundary Value Problems.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Problems with Floating-Point Representations Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright.
Introduction Examples of differential equations and related problems Analytical versus numerical solutions Ideas of numerical representations of solutions.
Boundary Value Problems l Up to this point we have solved differential equations that have all of their initial conditions specified. l There is another.
Modelling & Simulation of Chemical Engineering Systems Department of Chemical Engineering King Saud University 501 هعم : تمثيل الأنظمة الهندسية على الحاسب.
Decimal Numbers Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007 by Douglas Wilhelm Harder.
Double-Precision Floating-Point Numbers Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007.
Engineering Analysis – Computational Fluid Dynamics –
The Wave Equation Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Interpolation Search Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
Interpolating Solutions to IVPs Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 27.
Math 3120 Differential Equations with Boundary Value Problems
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
WATERLOO ELECTRICAL AND COMPUTER ENGINEERING Complaints, Discipline and Enforcement 1 WATERLOO ELECTRICAL AND COMPUTER ENGINEERING Professional Engineers.
1 The tree data structure Outline In this topic, we will cover: –Definition of a tree data structure and its components –Concepts of: Root, internal, and.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 N -ary trees This topic quickly looks at a generalization of a binary tree, where each node has up to N children –Definition –Perfect N -ary trees –Complete.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 Complete binary trees Outline Introducing complete binary trees –Background –Definitions –Examples –Logarithmic height –Array storage.
Chapter 30.
Outline In this topic we will look at:
Open Addressing: Quadratic Probing
AVL Trees.
Outline Introducing perfect binary trees Definitions and examples
Multiway Search Trees.
Boundary-value problems and Finite-difference equations
Presentation transcript:

MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011 by Douglas Wilhelm Harder. All rights reserved. Advanced Calculus 2 for Electrical Engineering Advanced Calculus 2 for Nanotechnology Engineering Method of Lines

2 Outline This topic introduces the method of lines –Used for solving heat-conduction/diffusion and wave equations –Finite differences discretizes both time and space –Discretize only space –Use a high-quality ODE solver to find the solution over time

Method of Lines 3 Outcomes Based Learning Objectives By the end of this laboratory, you will: –You will understand the method of lines –You will be able to implement it using the Matlab functions implemented in previous terms

Method of Lines 4 Integration-by-Parts in Higher Dimensions Up to this point, we have discretized both the space and time dimensions –We will look at another approach that discretizes only the space dimensions

Method of Lines 5 Discretizing in Space Consider the heat-conduction/diffusion equation Discretizing the space component in one dimension gives: We will demonstrate this only in one dimension; however, the generalization to 2 and 3 dimensions is obvious…

Method of Lines 6 Discretizing in Time With finite differences, we divided time into discrete steps, as well: which allowed us to find

Method of Lines 7 Review of Finite Differences We are given the initial state of the system by u init (x) Divide the space interval into n points with n – 1 intervals

Method of Lines 8 Review of Finite Differences We evaluate the initial state at each of the n points

Method of Lines 9 Review of Finite Differences Next, given these initial values, we take the finite-difference equation to approximate the state at the next time t 2 = t 1 +  t equatio –The boundary values are defined by functions a(t) and b(t)

Method of Lines 10 Review of Finite Differences Now, with this approximation, we approximate the values at times t 3, t 4, etc.

Method of Lines 11 Method of Lines As an alternative approach, associate with each spatial point an unknown function u k (t) –Two exceptions: u 1 (t) = a(t) u n (t) = b(t) This approach was popularized by the chemical engineer William E. Schiesser in his 1991 text The Numerical Method of Lines

Method of Lines 12 Method of Lines In order to substitute u k (t) into our mixed partial-/finite-difference equation, we note that the solution at location x – h is u k – 1 (t) and the solution at x + h is u k + 1 (t) : We also have the initial condition: u k (t initial ) = u init (x k )

Method of Lines 13 Systems of IVPs Therefore, we have a system of n – 2 initial-value problems but with n unknown functions:

Method of Lines 14 Systems of IVPs There are two unknown functions, however, these are given by our boundary conditions:

Method of Lines 15 Systems of IVPs We therefore have a system of n – 2 initial-value problems –With n = 9 :

Method of Lines 16 Systems of IVPs Note that we can rewrite the differential equations: Thus,

Method of Lines 17 Systems of IVPs We can therefore write this as: where

Method of Lines 18 IVP Solvers from Previous Courses From MATH 211, you implemented the function function [ ts, ys ] = dp45n( f, t_int, y1, h, eps_step) where t int = [t initial, t final ] that uses the adaptive Dormand-Prince method to approximate a solution to a system of initial-value problems where we allow a maximum error of  step where we start with an initial step size in time of h starting at t initial and going to t final

Method of Lines 19 IVP Solvers from Previous Courses We can write the function function du = f( t, u ) M = diag( -2*ones( n - 2, 1 ) ) +... diag( ones( n - 3, 1 ), 1 ) +... diag( ones( n - 3, 1 ), -1 ); du = (kappa/h^2)*(M*u + [a(t); zeros( n – 4, 1 ); b(t)]); end

Method of Lines 20 Example: Dirichlet Conditions To give a specific example, consider the following heat- conduction/diffusion problem: that is,  = 0.2, on [0, 1] with with n = 9 points

Method of Lines 21 Example: Dirichlet Conditions To give this a description: –A bar is initial uniform at 1 –For the first second, the left-hand side is placed in contact with a heat sink at 0, after which it is switched with a heat source of 2 –For the first two seconds, the right-hand side is in contact with a body also at 1, after which it is switched with a heat sink at 0

Method of Lines 22 Example: Dirichlet Conditions Thus, we have: function du = f111( t, u ) n = 9; M = diag( -2*ones( n - 2, 1 ) ) +... diag( ones( n - 3, 1 ), 1 ) +... diag( ones( n - 3, 1 ), -1 ); kappa = 0.2; h = 1/8; a > 1)); b < 2); du = (kappa/h^2)*(M*u + [a(t); zeros( n - 4, 1 ); b(t)]); end

Method of Lines 23 Example: Dirichlet Conditions This can be driven by: u_init + 1); a > 1)); b < 2); n = 9; xs = linspace( 0, 1, n )'; [ts, us] = [0, 3], u_init( xs(2:end - 1) ), 1, ); us = [a(ts); us; b(ts)]; mesh( ts, xs, us );

Method of Lines 24 Example: Dirichlet Conditions With two orientations, the output is the plot:

Method of Lines 25 Example: Dirichlet Conditions Note that  t is larger while the system converges but becomes smaller at the discontinuities

Method of Lines 26 Example: Insulated Conditions To give a specific example, consider the following heat- conduction/diffusion problem: that is,  = 0.2, on [0, 1] with and an insulated right-hand boundarywith n = 9 points

Method of Lines 27 Example: Insulated Conditions Using the 2 nd -order divided difference approximation of the derivative: and substituting our approximations for u(b, t), u(b – h, t), and u(b – 2h, t) equate this to zero, we have: or

Method of Lines 28 Example: Insulated Conditions We could then substitute into the last equation to get

Method of Lines 29 Example: Insulated Conditions Thus, we have: function du = f112( t, u ) n = 9; M = diag( -2*ones( n - 2, 1 ) ) +... diag( ones( n - 3, 1 ), 1 ) +... diag( ones( n - 3, 1 ), -1 ); M(n - 2, n - 2) = -2/3; M(n - 2, n - 3) = 2/3; kappa = 0.2; h = 1/8; a > 1); du = (kappa/h^2)*(M*u + [a(t); zeros( n - 4, 1 ); 0]); end Recall:

Method of Lines 30 Example: Insulated Conditions This can be driven by: u_init + 1); a > 1); n = 9; xs = linspace( 0, 1, n )'; [ts, us] = [0, 3], u_init( xs(2:end - 1) ), 1, ); us = [a(ts); us; (4*us(end,:) - us(end - 1,:))/3]; mesh( ts, xs, us );

Method of Lines 31 Example: Insulated Conditions With two orientations, the output is the plot:

Method of Lines 32 Example: Neumann Conditions Suppose that the right-hand side is a more general Neumann condition: Again, use the approximation and substituting our approximations for u(b, t), u(b – h, t), and u(b – 2h, t) equate this to zero, we have: or

Method of Lines 33 The Wave Equation We can also have an initial-value problem for the wave equation: This can, of course, be generalized to two and three dimensions: –There is one unknown function for each point

Method of Lines 34 The Wave Equation Recall that our function dp45.m only works with a 1 st -order differential equation –We must therefore convert the 2 nd -order ODE into a 1 st -order ODE

Method of Lines 35 The Wave Equation We therefore have a system of 2(n – 2) initial-value problems –With n = 9 :

Method of Lines 36 The Wave Equation Note that we can rewrite the differential equations:

Method of Lines 37 The Wave Equation We can therefore write this with :

Method of Lines 38 The Wave Equation Where the function f is defined as:

Method of Lines 39 The Wave Equation Thus, we have: function [dw] = f113( t, w ) n = 17; c = 1; h = 1/8; r = (c/h)^2; Id = ones( n - 2, 1 ); Id_off = ones( n - 3, 1 ); Z = zeros( n - 2, n - 2 ); M = diag( -2*r*Id ) + diag( r*Id_off, 1 ) + diag( r*Id_off, -1 ); M = [Z eye( n - 2, n - 2 ); M Z]; v = zeros( 2*n - 4, 1 ); a b v(n - 1) = r*a(t); v(end) = r*b(t); dw = M*w + v; end

Method of Lines 40 The Wave Equation This can be driven by: u_init du_init a b n = 17; xs = linspace( 0, 1, n )'; U_init = [u_init( xs(2:end - 1) ); du_init( xs(2:end - 1) )]; [ts, us] = 0, 10, U_init, 1, ); size( us ) u = [a(ts); us(1:(n - 2), :); b(ts)]; mesh( ts, xs, u ); du = [cos(3*ts); us((n - 1):end, :); 0*ts]; % Plot the derivative... mesh( ts, xs, du );

Method of Lines 41 The Wave Equation The plot of the solution and the derivative are here:

Method of Lines 42 Finite Element Methods It will also work equally effectively for finite element methods: –The elements define the relationship between a function defined at a point and its neighbouring functions

Method of Lines 43 Summary In this topic, we have covered the method of lines: –We discretize only the space component –This creates a system of initial-value problems –This may be solved using a high-accuracy adaptive ODE solver

Method of Lines 44 References [1]Schiesser, W. E., The Numerical Method of Lines, Academic Press, 1991.

Method of Lines 45 Usage Notes These slides are made publicly available on the web for anyone to use If you choose to use them, or a part thereof, for a course at another institution, I ask only three things: –that you inform me that you are using the slides, –that you acknowledge my work, and –that you alert me of any mistakes which I made or changes which you make, and allow me the option of incorporating such changes (with an acknowledgment) in my set of slides Sincerely, Douglas Wilhelm Harder, MMath