Numerical Solution of Engineering and Scientific Problems David M. Rocke Department of Applied Science
Numerical Solution of Engineering and Scientific Problems David M. Rocke Department of Applied Science
Numerical Solution of Engineering and Scientific Problems David M. Rocke Department of Applied Science
Solution of an Equation
We learn how to solve (find roots of) linear
and quadratic equations in
elementary/high school. Solution methods
for quadratics have been known for 4000
years.
Cubic and quartic equations have general
solutions (known since 1500s)
Quintic and higher polynomials have no
general solution
Quadratic Equations
ax + bx + c = 0
2
-b b - 4ac
x=
2a
2
gm
-( c / m ) t
v=
(1- e
)
c
gm
-( c / m ) t
f (c ) =
(1- e
)-v = 0
c
Bracketing Methods
Find two points xL and xU so that f(xL) and
f(xU) have opposite signs
If f() is continuous, there must be at least
one root in the interval
Bracketing methods take this information,
and produce successive approximations to
the solution by narrowing the interval
bracketing a/the root
Exceptions
Roots of multiplicity greater than one, count as
multiple roots in this. The function
f ( x ) ( x 1) 2
Bisection Method
Suppose a continuous function changes
sign between xL and xU. Consider
xM = (xL + xU)/2
If f(xM) = 0, we have found a root.
If f(xM) is not zero, it differs in sign from
exactly one of the end points
This gives a new interval of half the length
which must contain a root
gm
-( c / m ) t
f (c ) =
(1- e
)-v = 0
c
m = 68.1 kg
Reaches velocity of 40 m/s at t = 10s.
(9.8)(68.1)
-( c / 68.1)10
f (c ) =
(1- e
) - 40 = 0
c
667.38
-0.146843c
f (c ) =
(1- e
) - 40 = 0
c
f (12) = 6.06
f (16) = -2.269
f (14) = 1.569
f (15) = -0.425
f (14.5) = 0.5523
f (14.7802) = 0
14
-0.780
15
0.220
14.5
-0.280
0.5
14.75
-0.030
0.25
14.875
0.095
0.125
Function Evaluations
In some applications, evaluation of the
function to be minimized is expensive and
may itself involve a large computation
One example I am currently working on
takes about 15 minutes for each function
evaluation, each of which requires solving
400,000 subproblems
Optimize code to reduce function
evaluations
Summary of Bisection
The method is slow but sure for
continuous functions
There is a well-defined error bound,
though the true error may be much less
Fig 5.12
gm
-( c / m ) t
f (c ) =
(1- e
)-v = 0
c
m = 68.1 kg
Reaches velocity of 40 m/s at t = 10s.
(9.8)(68.1)
-( c / 68.1)10
f (c ) =
(1- e
) - 40 = 0
c
667.38
-0.146843c
f (c ) =
(1- e
) - 40 = 0
c
f (12) 6.0669
f (16) 2.2688
( 2.2688)(12 16)
xR 16
14.9113
6.0669 ( 2.2688)
f (14.9113) 0.2543
( 0.2543)(12 14.9113)
xR 14.9113
14.7942
6.0669 ( 0.2543)
f (14.7942) 0.02727
f (14.7802) 0
Fig 5.13
Bisection Error
Step
14
-0.780
15
0.220
14.5
-0.280
0.5
14.75
-0.030
0.25
14.875
0.095
0.125
14.9113
0.131104
14.7942
0.013994
0.117110
14.7817
0.001496
0.012497
14.78037
0.000164
0.001332
14.78023
0.000022
0.000142
Fig 5.14
Code Examples
We show pseudo code for modified false
position with adjustment of endpoint
function values
Then we show VBA code for false position
Then we show VBA code for the modified
false position as in the above pseudocode
Then VBA code for false position, with
bisection steps whenever the signs do not
change for a long time.
Fig 5.15
Option Explicit
Function f(x)
f = x ^ 10 - 1
End Function
Function FalsePos(xl, xu, es, imax)
Dim fl As Double, fu As Double, fr As Double
Dim xr As Double, xrold As Double, ea As Double, test As Double
Dim iter As Integer
iter = 0
fl = f(xl)
fu = f(xu)
If fl * fu >= 0 Then
MsgBox ("Function does not change sign in interval")
Return
End If
Do
xrold = xr
xr = xu - fu * (xl - xu) / (fl - fu)
fr = f(xr)
iter = iter + 1
If xr <> 0 Then
ea = Abs((xr - xrold) / xr)
End If
test = fl * fr
If test < 0 Then
xu = xr
fu = fr
ElseIf test > 0 Then
xl = xr
fl = fr
Else
ea = 0
End If
If (ea < es) Or (iter >= imax) Then
Exit Do
End If
Loop
FalsePos = xr
MsgBox ("ea = " & ea & " iter = " & iter)
End Function
Do
If test < 0 Then
xu = xr
fu = fr
iu = 0
il = il + 1
If il >= 2 Then
fl = fl / 2
End If
ElseIf test > 0 Then
xl = xr
fl = fr
il = 0
iu = iu + 1
If iu >= 2 Then
fu = fu / 2
End If
il = 0
iu = 0
test = fl * fr
If test < 0 Then
iu = 0
il = il + 1
If il >= 3 Then
xr = (xl + xr) / 2
fr = f(xr)
End If
ElseIf test > 0 Then
il = 0
iu = iu + 1
If iu >= 3 Then
xr = (xr + xu) / 2
fr = f(xr)
End If
End If
test = fl * fr