Sei sulla pagina 1di 20

# Introduction to Numerical Methods

Dr. Guoliang He

## School of Mathematical Sciences

501693164@qq.com

uestc 1
Reasons to study
 “Solve” problems with no analytic solution
Non-linear equations
Complex behaviors
 Understand these methods
Gain familiarity with common algorithms
Computing realities and calculations in
principle
 How they can be improved

## Numerical methods shouldn’t be used

blindly
uestc 2
Course outline
 Introduction, numerical aspects of
computing
 Finding roots of equations
 Curve fitting
 Matrix algebra
 Numerical integration and differential
 The numerical solution of ordinary
differential equations

uestc 3
What computers can’t do
 Solve (by reasoning) general mathematical
problems
 they can only repetitively apply
arithmetic primitives to input.
 Solve problems exactly.
 Represent all numbers.
Only a finite subset of the numbers
between 0 and 1 can be represented.
Binary  Denary
?
uestc 4
Finding roots / solving equations
 General solution exists for equations such as
ax2 + bx + c = 0
The quadratic formula provides a quick
 However, no exact general solution (formula)
exists for equations with exponents greater
than 4.

## Note: The solutions of equations with

exponents greater than 4 are all exist!
uestc 5
Finding roots…
 Even if “exact” procedures existed, we are
stuck with the problem that a computer can
only represent a finite number of values… thus,
we cannot “validate” our answer because it
will not come out exactly.
 However we can say how accurate our solution
is as compared to the “exact” solution.

##  Transcendental equations: involving geometric

functions (sin, cos), log, exp. These equations
cannot be reduced to solution of a polynomial.
uestc 6
Problem-dependent decisions
 Approximation: since we cannot have exactness,
we specify our tolerance to error

##  Convergence: we might imagine a “reasonable”

procedure for finding solutions, but can we
guarantee it terminates? we also specify how long
we are willing to wait for a solution

##  Method: we choose a method easy to implement

and yet powerful enough and general
Put a human in the loop: since no general procedure can find
roots of complex equations, we let a human specify a
neighbourhood of a solution
uestc 7
Practical approach - example

 Example
e -x = sin(x/2)
 Solve for x.
 Graph functions - the crossover points are
solutions
 This is equivalent to finding the roots of
the difference function:
f(x)= e -x - sin(x/2)

uestc 8
Graph

uestc 9
Graph

uestc 10
Solution, continued

##  One crossover point at about 0.5, another

at about 2.0 (there are very many of
them …)
 Compute values of both functions at 0.5
 Decrement/increment slightly – watch the
sign of the difference-function!!
 If there is an improvement continue, until
you get closer.
 Stop when you are “close enough”

uestc 11
Tabulating the function
Step x e-x sin(1/2x) f(x)= e-x -
sin(1/2x)
0 0.3 0.741 0.454 0.297
1 0.4 0.670 0.588 0.082
2 0.5 0.606 0.707 - 0.101
3 0.45 0.638 0.649 - 0.012
4 0.425 0.654 0.619 0.0347
5 0.4375 0.6456 0.6344 0.01126
6 0.44365 0.6417 0.6418 - 0.00014

uestc 12
Bisection Method

##  The Bisection Method slightly modifies

“educated guess” approach of hand
calculation method.
 Suppose we know a function has a root
between a and b. (…and the function is
continuous, … and there is only one root)

uestc 13
Bisection Method

##  Keep in mind general approach in

Computer Science: for complex problems
we try to find a uniform simple systematic
calculation
 How can we express the hand calculation
of the preceding in this way?
 Hint: use an approach similar to the
binary search…

uestc 14
Bisection Method—Basic Idea

uestc 15
Bisection method—Algorithm
 Check if solution lies between a and b…
F(a)*F(b) < 0 ?
 Try the midpoint m: compute F(m)
 If |F(m)| < tol select m as your approximate
solution
 Otherwise, if F(m) is of opposite sign to F(a) that
is if
F(a)*F(m) < 0, then b = m.
Else a = m.
uestc 16
Bisection method—Example
 This method converges to any pre-
specified tolerance when a single root
exists on a continuous function

##  Example Exercise: write a function that

finds the square root of any positive
number that does not require programmer
to specify estimates

uestc 17
Square root program

##  If the input c < 1, the root lies between c

and 1.
 Else, the root lies between 1 and c.
 The (positive) square root function is
continuous and has a single solution.
6

4
c = x2
Example: 2

F(x) = x2 - 4 -2
0 0.5 1 1.5 2 2.5 3

-4

-6
F(x) = x2 - c
uestc 18
6

0
0 0.5 1 1.5 2 2.5 3
-2

-4

-6

uestc 19
References
 John H. Mathews and Kurtis D. Fink, Numerical
Methods Using MATLAB, 4th ed
 Numerical Methods Using MATLAB, 4th edition
John H. Mathews and Kurtis D. Fink,黄仿伦