You are on page 1of 37

AOE 2074

Computational Methods

Parts 1–2
Chapters 1–7

Summary

All images copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
In-Class Test #1 – Thursday, Sept 30

•  Test #1 Covers •  First Part (60%)


•  Chapters 1-7 •  30 Questions
•  Tutorials 1-3 •  Multiple Choice, T/F
•  HW#1-5 •  Scantron
•  Forbidden •  No MATLAB or Laptop
•  Closed Book/Notes •  Second Part (40%)
•  No Calculator •  4 Problems
•  No Cell Phone •  MATLAB
•  Required •  Upload to Scholar
“Tests & Quizzes”
•  Laptop & Battery
•  Proctored in CL
2
Introduction (Chapters 1–2)

1.  Overview of Numerical Methods


•  Mathematical Models
•  Analytical vs. Numerical Methods
•  Physical Laws
2.  MATLAB Fundamentals
•  Assignment of Real and Complex Values
•  Creating Vectors and Matrices
•  Vector and Matrix Operations
•  Basic Graphics
3
Mathematical Model

•  Expresses essential features of a physical system or


process in mathematical terms
•  Functional relationship between dependent variables,
independent variables, parameters, and forcing functions.
y = f ( x, p, r)

•  y: Dependent variable—a characteristic that usually reflects the behavior


or state of the system
•  x: Independent variables—dimensions, such as time and space, along
which the system’s behavior is being determined
•  p: Parameters—constants reflective of the system’s properties
•  r: Forcing function— external influences acting upon the system

4
Matrix Operations

Scalar Multiplication

The dot (.) operator specifies the operation is element-by-element.

Matrix Multiplication

5
Chapter 3: MATLAB Fundamentals

Input / Decision
M-files Loops
Output Structures
•  Script •  disp •  if, elseif, else •  for
•  Function •  fprintf •  switch case •  while
•  Subfunctions •  save
(nested) •  load
•  Anonymous
•  In-Line
•  Handles

Order of Operations Vectorization

6
Function Files

•  Function files serve different purpose from script files.


–  accept input arguments from command window
–  return outputs to the command window
–  But variables created and manipulated within the
function do not impact
the command window.

7
Algorithms Review

•  Precise, step-by-step set of instructions for a task


•  Valid Algorithms must be…
  Unambiguous – interpreted in one unique way
  Executable – accomplish without extra information
  Ordered – steps given in proper sequence
to correctly accomplish the task
•  Algorithmic Thinking
  Understand, Execute, Evaluate, Create algorithms
  Communicated by Precise (Computer) Language
Outlined less precisely by Pseudo Code
  Represented visually by Flow Charts
Applies to any computer language
8
Algorithms Review (cont.)

•  Properties
  Not Unique (many for a non-trivial task)
  Devoid of Theory for the Instructions
  Some Algorithms more Efficient than Others
  Modified Often
•  Principles for Creating an Algorithm
1.  Solve a specific instance of the problem by hand
2.  Generalize solution with variables
3.  Execute the algorithm on several test cases
to verify that it produces correct answers
4.  Write correct programming statements
to implement the general solution on a computer
9
Structured Programming

  Decisions: if condition if condition


Statements Statements
end elseif condition
Statements
if condition elseif condition
Statements Statements
else …
Statements else
end Statements
end
  For Loop

  While Loop while condition


Statements
end

10
Chapter 4: Roundoff & Truncation
Errors

Roundoff

Errors Truncation Model

Other Uncertainty

Mistakes
11
Error Definitions

Error Type True Approximate

Et = True Value – Estimate Present – Previous Estimate

Absolute | Et | | Present – Previous Est. |

Fractional Relative Et / True Value (Present – Previous) / Present

Percent Relative Et / True Value × 100% εa = (Present–Previous) /


Present × 100%

Absolute (Percent) | Et / True Value | × 100% εa = | (Present–Previous) /


Relative Present | × 100%

12
Total Numerical Error

•  The total numerical error =


truncation + roundoff errors
•  Truncation error generally
increases as the step size increases,
•  Roundoff error
decreases as the step size increases
•  Leads to a point of diminishing returns
for step size.

13
Chapters 5–6: Roots

Root Finding
Methods

Graphical Bracketing Open Hybrid

Incremental Fixed Point MATLAB’s


Search Iteration fzero

Newton-
Bisection
Raphson

False
Position 14
Graphical Methods

•  Make a plot of the function f(x)=0


and observe where it
crosses the x-axis.
•  Graphing the function can also
indicate where roots may be and
where some root-finding methods
may fail:
a)  Same sign, no roots
b)  Different sign, one root
c)  Same sign, two roots
d)  Different sign, three roots

15
Bracketing Methods

•  Graphical method provides


rough estimation

•  Bracketing Methods
–  Can find a root more exactly
(up to a desired relative error)
–  Require two initial estimates
which bracket the root
16
Open Methods

•  Open methods require only a single starting value or two


starting values that do not necessarily bracket a root,
in contrast to bracketing methods.
–  Open methods
may diverge!
–  When they converge,
usually much faster

a)  Bracketing method


b)  Diverging open method
c)  Converging open method
•  note speed!
17
Chapter 7: Optimization

Golden
Section

Quadratic
1-D
Interpolation

fminbnd
Optimization
Methods
Contour
Graphical
Multi-
Surface
Dimensional
fminsearch
18
Equations to Memorize

•  Significant Digits for Stopping Criterion (4.7)


•  Taylor Series (4.13)
•  False Position Formula (5.7)
•  Fixed Point Iteration Formula (6.2)
•  Newton-Raphson Formula (6.6)
•  Secant Method (6.8)
•  Modified Secant Method (6.9)
•  Golden Ratio (7.4) & Search (7.6–8)

19
Sample Test Questions

•  Pencil and Paper?


•  6 Questions for Part 1
  30-40 seconds per question
•  1 Question for Part 2

20
Sample Question #1

A mathematical model expresses essential features


of a physical system or process in mathematical
terms.

A. True

B. False

21
Sample Question #2

⎡ 1 ⎤ ⎡ −1 ⎤
•  Given ⎢ ⎥ ⎢ ⎥
a = ⎢ 2 ⎥, b=⎢ 0 ⎥
⎢⎣ 3 ⎥⎦ ⎢⎣ 1 ⎥⎦
What is the result of the operation c = a T
b = a '* b ?
A.  c=2

⎡ −1 ⎤
B.  c=⎢ 0 ⎥
⎢ ⎥
⎢⎣ 3 ⎥⎦

⎡ −1 0 1 ⎤
C.  c = ⎢ −2 0 2 ⎥
⎢ ⎥
⎢⎣ −3 0 3 ⎥⎦ 22
Sample Question #3

Algorithmic Thinking...

A.  is synonymous with computer programming

B.  may be represented by a flow chart

C. is the result of pseudo code

D. cannot be tested

23
Sample Question #4

Roundoff error decreases as the step size increases.

A. True

B. False

24
Sample Question #5

The bisection method of finding roots of nonlinear


equations falls under the category of a (an)
_________ method.

A.  open

B.  bracketing

C. random

D. graphical

25
MATLAB (2nd) Part

•  The first iterative value of the root of f (x) = x2–4=0,


using the false position method, if bracketed on [1, 3],
is __________ .

26
AOE 2074
Computational Methods

Part 3
Chapter 8

Linear Algebraic
Equations and
Matrices
http://www.youtube.com/watch?v=gUgyY16UWAM

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University & edited by Dr. Robert A. Canfield, Virginia Tech
27

All images copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 8 Objectives

•  Understand matrix notation.


•  Identify following types of matrices: identity,
diagonal, symmetric, triangular, and tridiagonal.
•  Know how to perform matrix multiplication and be
able to assess when it is feasible.
•  Know how to represent a system of linear equations
in matrix form.
•  Knowing how to solve linear algebraic equations
with left division and matrix inversion in MATLAB.

Covered week after in-class test #1


28
Matrix Algebra Review

To solve a System of Linear


Algebraic Equations (SLAE) we
need to review matrix algebra

Fundamentals of Matrix Algebra and Notations


should be familiar to you, including the facts on the
following pages

29
Matrix Notation

An m×n matrix

•  A matrix consists of a rectangular array of elements


represented by a single symbol (example: [A]).
•  An individual entry of a matrix is an element (example: a23) 30
Matrix Notation (cont’d.)

•  A horizontal set of elements is called a row and a


vertical set of elements is called a column.
•  The first subscript of an element indicates the row
while the second indicates the column.
•  The size of a matrix is given as m rows by n
columns, or simply m by n (or m x n).
•  1×n matrices are row vectors.
•  m×1 matrices are column vectors.

31
Square Matrices

•  Matrices where m=n are called square matrices.


•  Special forms of square matrices:

32
Matrix Types

•  Example of a 3×3 matrix:


–  Diagonal matrix:

–  Identity Matrix:
–  Multiplication with
Identity Matrix:

–  Matrix Inverse:

–  Transpose
33
Matrix Inverse and Transpose

•  The inverse of a square, nonsingular matrix [A] is that


matrix which, when multiplied by [A], yields the identity
matrix.
  [A][A]-1=[A]-1[A]=[ I ]
•  The transpose of a matrix involves transforming its rows
into columns and its columns into rows.
  (aij)T=aji

34
Matrix Operations

•  Two matrices are considered equal


–  if and only if every element in the first matrix is equal to
every corresponding element in the second.
–  Means the two matrices must be same size.
•  Matrix addition and subtraction
–  performed by adding or subtracting the corresponding
elements.
–  Requires the two matrices be the same size.
•  Scalar (or elementwise) matrix multiplication
–  Performed by multiplying each element
by the same scalar—matrices must be same size.
35
Matrix Multiplication

•  The elements in the matrix [C] that results from multiplying


matrices [A] and [B] are calculated using:

Matrix Multiplication
Matrices must be Conformal 36
Properties of Matrix Multiplication

•  Matrix Multiplication is
–  Non-commutative
–  Distributive
–  Associative

37

You might also like