Introduction to Numerical Methods
and Matlab Programming for Engineers
Todd Young and Martin J. Mohlenkamp
Department of Mathematics
Ohio University
Athens, OH 45701
young@math.ohiou.edu
August 27, 2011
ii
Copyright c 2008, 2009, 2011 Todd Young and Marti
Lecture 33
ODE Boundary Value Problems and
Finite Dierences
Steady State Heat and Diusion
If we consider the movement of heat in a long thin object (like a metal bar), it is known that the
temperature, u(x, t), at a location x and time t satises the parti
Lecture 31
Higher Order Methods
The order of a method
For numerical solutions of an initial value problem there are two ways to measure the error. The
rst is the error of each step. This is called the Local Truncation Error or LTE. The other is the
total
Lecture 30
Euler Methods
Numerical Solution of an IVP
Suppose we wish to numerically solve the initial value problem
y = f (t, y),
y (a) = y 0 ,
(30.1)
on an interval of time [a, b].
By a numerical solution, we must mean an approximation of the solution a
Lecture 29
Reduction of Higher Order Equations to
Systems
The motion of a pendulum
Consider the motion of an ideal pendulum that consists of a mass m attached to an arm of length .
If we ignore friction, then Newtons laws of motion tell us:
mg
sin ,
m =
Lecture 28
The Main Sources of Error
Truncation Error
Truncation error is dened as the error caused directly by an approximation method. For instance,
all numerical integration methods are approximations and so there is error, even if the calculations
are
Lecture 27
Numerical Dierentiation
Approximating derivatives from data
Suppose that a variable y depends on another variable x, i.e. y = f (x), but we only know the values
of f at a nite set of points, e.g., as data from an experiment or a simulation:
(x
Lecture 25
Double Integrals for Non-rectangles
In the previous lecture we considered only integrals over rectangular regions. In practice, regions of
interest are rarely rectangles and so in this lecture we consider two strategies for evaluating integrals
Lecture 34
Finite Dierence Method Nonlinear
ODE
Heat conduction with radiation
If we again consider the heat in a metal bar of length L, but this time consider the eect of radiation
as well as conduction, then the steady state equation has the form
uxx d(
Lecture 35
Parabolic PDEs - Explicit Method
Heat Flow and Diusion
In the previous sections we studied PDE that represent steady-state heat problem. There was no
time variable in the equation. In this section we begin to study how to solve equations that i
Part III
Functions and Data
c Copyright, Todd Young and Martin Mohlenkamp, Mathematics Department, Ohio University, 2007
Lecture 19
Polynomial and Spline Interpolation
A Chemical Reaction
In a chemical reaction the concentration level y of the product at
Part II
Linear Algebra
c Copyright, Todd Young and Martin Mohlenkamp, Mathematics Department, Ohio University, 2007
Lecture 8
Matrices and Matrix Operations in
Matlab
Matrix operations
Recall how to multiply a matrix A times a vector v:
Av =
12
34
1
2
1 (
Part I
Matlab and Solving Equations
c Copyright, Todd Young and Martin Mohlenkamp, Mathematics Department, Ohio University, 2007
Lecture 1
Vectors, Functions, and Plots in Matlab
In this book > will indicate commands to be entered in the command window. Y
Lecture 42
Determining Internal Node Values
As seen in the previous section, a nite element solution of a boundary value problem boils down to
nding the best values of the constants cfw_Cj n=1 , which are the values of the solution at the nodes.
j
The int
Lecture 41
Finite Elements
Triangulating a Region
A disadvantage of nite dierence methods is that they require a very regular grid, and thus a very
regular region, either rectangular or a regular part of a rectangle. Finite elements is a method that
works
Lecture 39
Finite Dierence Method for Elliptic
PDEs
Examples of Elliptic PDEs
Elliptic PDEs are equations with second derivatives in space and no time derivative. The most
important examples are Laplaces equation
u = uxx + uyy + uzz = 0
and the Poisson eq
Lecture 38
Insulated Boundary Conditions
Insulation
In many of the previous sections we have considered xed boundary conditions, i.e. u(0) = a,
u(L) = b. We implemented these simply by assigning uj = a and uj = b for all j .
n
0
We also considered variabl
Lecture 37
Implicit Methods
The Implicit Dierence Equations
By approximating uxx and ut at tj +1 rather than tj , and using a backwards dierence for ut , the
equation ut = cuxx is approximated by
ui,j +1 ui,j
c
= 2 (ui1,j +1 2ui,j +1 + ui+1,j +1 ).
k
h
(3
Lecture 23
Plotting Functions of Two Variables
Functions on Rectangular Grids
Suppose you wish to plot a function f (x, y ) on the rectangle a x b and c y d. The graph
of a function of two variables is of course a three dimensional object. Visualizing the
Lecture 22
Integration: Midpoint and Simpsons
Rules
Midpoint rule
If we use the endpoints of the subintervals to approximate the integral, we run the risk that the values
at the endpoints do not accurately represent the average value of the function on th
Lecture 10
Some Facts About Linear Systems
Some inconvenient truths
In the last lecture we learned how to solve a linear system using Matlab. Input the following:
> A = ones(4,4)
> b = randn(4,1)
> x = A\b
As you will nd, there is no solution to the equat
Lecture 9
Introduction to Linear Systems
How linear systems occur
Linear systems of equations naturally occur in many places in engineering, such as structural analysis, dynamics and electric circuits. Computers have made it possible to quickly and accura
Lecture 8
Matrices and Matrix Operations in
Matlab
Matrix operations
Recall how to multiply a matrix A times a vector v:
Av =
12
34
1
2
1 (1) + 2 2
3 (1) + 4 2
=
=
3
5
.
This is a special case of matrix multiplication. To multiply two matrices, A and B yo
Lecture 7
Symbolic Computations
The focus of this course is on numerical computations, i.e. calculations, usually approximations,
with oating point numbers. However, Matlab can also do symbolic computations which means
exact calculations using symbols as
Lecture 6
Secant Methods*
In this lecture we introduce two additional methods to nd numerical solutions of the equation
f (x) = 0. Both of these methods are based on approximating the function by secant lines just as
Newtons method was based on approximat
Lecture 5
The Bisection Method and Locating
Roots
Bisecting and the if .
else .
end statement
Recall the bisection method. Suppose that c = f (a) < 0 and d = f (b) > 0. If f is continuous,
then obviously it must be zero at some x between a and b. The bise
Lecture 4
Controlling Error and Conditional
Statements
Measuring error
If we are trying to nd a numerical solution of an equation f (x) = 0, then there are a few dierent
ways we can measure the error of our approximation. The most direct way to measure th