Anda di halaman 1dari 35

Introduction

ES 84 Numerical Methods

Motivation
Two main methods of solving an engineering problem:
1. Analytical methods
Provide the exact solution for the equation(s) governing the engineering system.
Give insight to the behavior of the system.

Usually not applicable to complex geometries and/or systems with nonlinear behavior why?

2. Numerical methods
Provide a numerical result that is an approximation of the exact solution.
Can be used to analyze complex geometries and/or nonlinear systems
Requires tedious iterative computations

Example 1: Velocity of a Falling Sphere


Governing equation:

Assume drag force is proportional to the velocity:

Knowns: m, g, CD (drag coefficient) Unknown: v = v(t)


Analytically solve the differential equation to obtain:

Analytical solution clearly shows the effect of each parameter on v.


However, it is not always possible to obtain an analytical solution.

Example 1 continued: A more realistic drag force


Governing equation:

In reality, FD is not proportional to v.

Equation has become nonlinear not possible to solve analytically.


Numerical solution: dv/dt can be approximated by the following

In this course we will learn how to use the above approximation and similar
approximations to solve equations.

What Are We Going to Learn


Finding roots of nonlinear equations
Solving linear algebraic systems of equations

Optimization
Curve fitting and interpolation
Numerical differentiation
Numerical integration
Solving Ordinary Differential Equations (ODE)

Finding Roots of Nonlinear Equations


Consider the falling sphere example again. For the
FD = CDv(t) assumption, the solution was:

An experiment is done and velocity is measured as:


v(t = 10 s) = 40 m/s.
Knowns: v for given t, g, m Unknown: CD

f (CD) = 0
Problem: What is the drag
coefficient, CD?
Is it possible to solve
analytically for CD?

Solving Linear Algebraic Systems of Equations


The schematic is a thermal
model of a computer chip
with uniform heat generation.
Problem: What is the steady-state
2D temperature distribution of the chip?

The differential equation can


discretized using finite
element analysis.
Each grid point is an unknown
temperature (9 unknowns).

q : heat generation rate per unit volume


k : thermal conductivity of the plate

Solving Linear Algebraic Equations (continued)


The finite element discretization results in the following set of algebraic equations.

Ti : the temperature at node i,

a : length of one side of the chip,

q : heat generation rate per volume,

k : thermal conductivity of the plate.

Curve Fitting and Interpolation


Tool life experiments were performed during machining
of AISI-4140 steel.

Problem: Estimate the tool life for the cutting speed of 190 m/min.
Which of the below two approaches more suitable for this problem?

Numerical Differentiation
Measured velocity of a car during a crash test.

Velocity, Vx (inches/s)

X 100

Problem: What is the


maximum acceleration
of the car?

Time (s)
Data and video: http://rockyroer.blogspot.com.tr/2011/11/crash-test-data.html

Numerical Integration
The cross section of a racing
sailboat is shown.
The sails apply a distributed load
on the mast.
Problem: What is the total force
on the mast?

F is in lb/ft.

Solution of ODEs
The mirror of a solar heater
All the incident light rays should reflect
through a single point (focus).
The shape of the mirror is governed by the
equation:

Problem: What should be the shape


equation of the mirror, y(x)?

Programming
Algorithm: Sequence of logical steps required to perform a specific task.

Pseudocode: Written description of a program.


Flowchart: Visual / graphical representation of a program.

Example 2: Write a computer program to calculate sin(x) using the following series
expansion.

Algorithm

Pseudocode, Flowchart
Pseudocode
INPUT x, N
SIN = 0
LOOP k from 1 to N
SIN = SIN + (-1)k+1* x2k-1/ (2k-1)!
END LOOP
OUTPUT x, SIN

Programming Errors (Bugs)


Syntax error

Will not compile. Compiler will help you to find it.


e.g. writing x = inp('x: ') instead of x = input('x: ').
Run-time error
Will compile but stop running at some point.
e.g. division by zero or trying to read from a non-existing file.
Logical error
Will compile and run, but the result is wrong.
e.g. in the sin(x) example taking all the terms as positive.
Especially the last two types need careful debugging of the program.

Hints About Programming


Clarity
put header:
author, date, version, purpose, variable definitions, etc.

put comments:
explain variables, purpose of code segments, etc.

Testing
run with typical data
run with unusual but valid data
run with invalid data to check error handling

Programming (continued)
What do you need to know about programming?
Basic programming skills that you studied in CSc 101
Scilab syntax
data types (integers, single vs. double precision, arrays, etc.)
loops, if statements
input / output
etc.
Advice on learning SCILAB
Refresh your programming knowledge by studying the Scilab tutorials.
Approach the problem through the algorithm-pseudocode-computer code sequence.
See the course web site for other useful links.

Significant Figures
Designate the reliability of a number.
Number of significant figures to be used in a number depends
on the origin of the number.
Consider the calculation of the area of a circle, A = D2/ 4

Loss of Significance during Calculations


Classical example is the subtraction of two very close numbers.

Example 3: Calculate x sin(x) for x = 1 / 15.


x
= 0.6666666667 * 10-1
sin(x) = 0.6661729492 * 10-1
x-sin(x) = 0.0004937175 * 10-1
First four zeros are not significant. They are used just to place the
decimal point properly.

In other words if we represent this result as:


0.4937175000 * 10-4,then the last 4 digits have error.
The result should be 0.4937174327 * 10-4.

Accuracy and Precision


Accuracy: How closely
computed or measured
values agrees with the
true value.

Precision: How closely


computed or measured
values agree with each
other.

Error Definitions (very important)


True Error
True Error: Et= True Value Approximate Value
Relative True Error (fractional): t = Et / True Value
Relative True Error (percentage): t= (Et / True Value) * 100%

(preferred)

Approximate Error
Approximate Error: Ea= Present Approx Value Past Approx Value
Relative Approximate Error (fractional):
a= Ea / Present Approx Value
Relative Approximate Error (percentage):
a= (Ea / Present Approx Value) * 100%

(preferred)

Error Definitions (continued)


Tolerance:
Many numerical methods work in an iterative fashion.
There should be a stopping criterion for these methods.
We stop when the error level drops below a certain tolerance value
(s) that we select such that | a|< s

Scarborough criteria:
If the tolerance is selected to be s= 0.5x102-n%, then the
approximation is guaranteed to be correct to at least n digits(see
Problem 3.10, 6thed).

Types of Error
Round-Off Errors
Computers cannot use infinite number of digits to store numbers.
Conversion from base 10 to base 2 may create problems.
(0.1)10= (0.00011 00011 00011 00011 )2
Some numbers such as or 1/3 can not be represented exactly.

Floating point numbers can be stored as single (7-8 digits) or double


precision (15-16). Double precision storage reduces round-off errors.
Round-off errors cannot be totally eliminated but clever algorithms
may help to minimize them.
Round-off errors have accumulative behavior.

Types of Error Examples


Example 4: Add 0.1 thousand times. Use both double and single precision.
Compare the results (Double precision will give the exact answer of 100, but single
precision will not)
Example 5:
Calculate the following series by computing the sum from 1 to N = 10000 using
increments of 1.

Repeat the calculation using increments of -1. Adding numbers starting from the
smallest is known to result in less round-off error.

Types of Error (continued)


Truncation Errors

Due to the use of an approximation instead of an exact mathematical procedure.


For example, calculating the sine of a number using finite number of terms from an
infinite series will result in truncation error.
Example 6: Calculate
0.001 %.

for x= / 2. Stop when a <

Types of Error (summary)


Two main types:
Round-off error
Truncation error
Important:
Round-off and truncation errors generally appear together.

As we add more terms, truncation error drops.


But at some point round-off error starts to dominate due to its
accumulative behavior and total error will start to increase.

Taylor Series (very important)


Taylor Series (TS) is the basics of this course. It is simply used to evaluate a function
at one point, using the value of the function and its derivatives at another point.

Taylor Series Big O Notation

Taylor Series
Example:
Evaluate f(x) = x4 using first order Taylor series approximation around xi = 1 for
different values of h.

Read Chapra & Canale Chapter 4: Truncation Errors and Taylor Series

Taylor Series Generalization

This is the nth order Taylor series approximation of f(xi+1) around x i.


Rn is the remainder (truncation error).

nth order Taylor series expansion will be exact if f(x) is an nth order polynomial. Rn
will have (n+1)th derivative which is zero.

In general, approximations for f(xi+1) gets better as the order of the approximation
increases, and as h decreases.
If the expansion is around zero, then it is called the Maclaurin Series.

Example Maclaurin Series


Example 7: Derive the following Maclaurin series. Separately evaluate
them at x = 0.5 and x = 5 using 1 5 terms and compare the
convergence rates.

Error Propagation
How does error propagate in mathematical formulae?
For functions of a single variable, f(x):

Example 8:

Error Propagation Multiple Variables


For functions of multiple variable, f(u,v):

Example 9:
Wind tunnel experiments on a
race car were performed to
understand its drag
characteristics
Determine the error in the drag
coefficient using the data
provided.

What did we learn?


Difference between analytical and numerical methods
The purpose of numerical methods
Programming Review
Algorithm
Pseudocode
Flowchart

Mathematical Definitions
Significant figures

Sources of error

Accuracy and precision

Taylor series

True error and approximate error

Error propagation

Read Chapra and Canale Part One for more details.


What is next?
Finding Roots of Nonlinear Equations (Chapra and Canale, Part Two)

END

Anda mungkin juga menyukai