Numerical Methods in Engineering (ENGR20005)
Lecture 02 Dr. Leon Chan
lzhchan@unimelb.edu.au Department of Mechanical Engineering The University of Melbourne
Slides prepared by Prof.Andrew Ooi
L1.4 Taylor Series (Page 7 of Book)
Taylor Series
The Taylor series expansion of a function f(x) about the point x0 and can be written as
f(x)=! f(k)(x0)(x”x0)k k=0 k!
= f(x0) + f#(x0)(x ” x0) + f##(x0) (x ” x0)2 + f (###)(x0) (x ” x0)3 + $+ 2! 3!
In reality, you cannot sum to infinity.
(1.1)
f(x) = PN(x) + RN(x) where N f (k)(x0) k
PN(x) = !k=0 k! (x ” x0)
PN(x) RN(x)
RN(x) = f (N+1)(!(x)) (x ” x0)N+1 (N+1)!
is the Nth order Taylor Polynomial for f
is the remainder which is also known as the truncation error. !(x) is a number between x and x0, i.e. x % !(x) % x0
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ” x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ” x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f #(!(x))(x ” x0)
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f#(x0)(x ” x0)
R1(x) = f ##(!(x)) (x ” x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f##(x0) 2 f###(!(x)) P2(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) R2(x)= 3! (x”x0)3
For N=3
f(x) = P3(x) + R3(x) f##(x0) 2 f###(x0) 3 fiv(!(x)) P3(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) + 3! (x”x0) R3(x)= 4! (x”x0)4
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ” x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ” x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f #(!(x))(x ” x0)
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f#(x0)(x ” x0)
R1(x) = f ##(!(x)) (x ” x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f##(x0) 2 f###(!(x)) P2(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) R2(x)= 3! (x”x0)3
For N=3
f(x) = P3(x) + R3(x) f##(x0) 2 f###(x0) 3 fiv(!(x)) P3(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) + 3! (x”x0) R3(x)= 4! (x”x0)4
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ” x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ” x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f #(!(x))(x ” x0)
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f#(x0)(x ” x0)
R1(x) = f ##(!(x)) (x ” x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f##(x0) 2 f###(!(x)) P2(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) R2(x)= 3! (x”x0)3
For N=3
f(x) = P3(x) + R3(x) f##(x0) 2 f###(x0) 3 fiv(!(x)) P3(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) + 3! (x”x0) R3(x)= 4! (x”x0)4
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ” x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ” x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f #(!(x))(x ” x0)
As we increase N,
P has more terms
and become polynomial of order N
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f#(x0)(x ” x0)
R1(x) = f ##(!(x)) (x ” x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f##(x0) 2 f###(!(x)) P2(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) R2(x)= 3! (x”x0)3
For N=3
f(x) = P3(x) + R3(x) f##(x0) 2 f###(x0) 3 fiv(!(x)) P3(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) + 3! (x”x0) R3(x)= 4! (x”x0)4
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ” x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ” x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f #(!(x))(x ” x0)
As we increase N,
the remainder (or error) term becomes smaller and smaller near x=x0
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f#(x0)(x ” x0)
R1(x) = f ##(!(x)) (x ” x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f##(x0) 2 f###(!(x)) P2(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) R2(x)= 3! (x”x0)3
For N=3
f(x) = P3(x) + R3(x) f##(x0) 2 f###(x0) 3 fiv(!(x)) P3(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) + 3! (x”x0) R3(x)= 4! (x”x0)4
f(x) = PN(x) + RN(x)
PN(x) = !N f (k)(x0) (x ” x0)k k=0 k!
RN(x) = f (N+1)(!(x)) (x ” x0)N+1 (N+1)!
For N=0
f(x) = P0(x) + R0(x)
P0 = f (x0) R0(x) = f #(!(x))(x ” x0)
For N=1
f(x) = P1(x) + R1(x)
P1(x) = f(x0) + f#(x0)(x ” x0)
R1(x) = f ##(!(x)) (x ” x0)2 2!
For N=2
f(x) = P2(x) + R2(x) f##(x0) 2 f###(!(x)) P2(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) R2(x)= 3! (x”x0)3
For N=3
f(x) = P3(x) + R3(x) f##(x0) 2 f###(x0) 3 fiv(!(x)) P3(x)=f(x0)+f#(x0)(x”x0)+ 2! (x”x0) + 3! (x”x0) R3(x)= 4! (x”x0)4
Taylor series illustration
f(x) = PN(x) + RN(x) f(x)
x0 = 0
Taylor series illustration
f(x) = P0(x) + R0(x) f(x)
x0 = 0
P0 = f(x0)
R0(x) = f #(!(x))(x ” x0)
Taylor series illustration
f(x) = P1(x) + R1(x) f(x)
x0 = 0
P1(x) = f(x0) + f#(x0)(x ” x0)
R1(x)= f##(!(x))(x”x0)2 2!
Taylor series illustration
f(x) = P2(x) + R2(x) f(x)
x0 = 0
P2(x) = f(x0) + f#(x0)(x ” x0) + f##(x0) (x ” x0)2 ###
2! R2(x) = f (!(x))(x ” x0)3 3!
Taylor series illustration
R3(x) = f iv (!(x))(x ” x0)4 4!
x0 = 0
f(x) = P3(x) + R3(x) f(x)
P3(x) = f(x0) + f#(x0)(x ” x0) + f##(x0) (x ” x0)2 + f###(x0) (x ” x0)3 2! 3!
Taylor series illustration
f(x) x0 = 1
Taylor series illustration
x0 = 1 R0(x) = f #(!(x))(x ” x0)
f(x) = P0(x) + R0(x) f(x)
P0 = f(x0)
Taylor series illustration
x0 = 1 R1(x) = f ## (!(x))(x ” x0)2
f(x) = P1(x) + R1(x) f(x)
2!
P1(x) = f(x0) + f#(x0)(x ” x0)
Taylor series illustration
x0 = 1 R2(x) = f ### (!(x))(x ” x0)3
f(x) = P2(x) + R2(x) f(x)
3!
P2(x) = f(x0) + f#(x0)(x ” x0) + f##(x0) (x ” x0)2 2!
Taylor series illustration
x0 = 1 R2(x) = f iv (!(x))(x ” x0)4
f(x) = P3(x) + R3(x) f(x)
4!
P3(x) = f(x0) + f#(x0)(x ” x0) + f##(x0) (x ” x0)2 + f###(x0) (x ” x0)3 2! 3!
f(x) = P (x) + R (x) 0312 0312
f#(x ) f###(x )
0 2 0 3
P P ( =x ) f = ( x f ( ) x ) + f # ( x ) ( x ” x )
P(x)=f(x)+f#(x)(x”x)+ (x”x) + (x”x)
01 00 0 0
32 0 0 0 2! 0 3! 0
x0 = 0
f (x)
f (x)
x0 = 1
Example L01.1: Find the Taylor series of the function
f(x) = sin(x)
about x0=0. Plot the first few terms of this function and show that you can get closer to the original function if you use more and more terms in the series.
Want to find the Taylor series for
f(x) = sin(x)
The general formula for Taylor series is (see Eq. (1.1))
f(x) = f(x0) + f#(x0)(x ” x0) + f##(x0)(x ” x0)2 + f###(x0)(x ” x0)3 + $+ 2! 3!
Using, Eq. (1.1), expand the function about x0=0. the Taylor series for sin(t) can be written as
x
### f##(x ) f (x )
00 0
xxx0x200x3 f(x)=f(x0)+f#(x0)(x”x)+ (x”x) + (x”x) +$+
000
00000 0 0 0 2! 0 3! 0
x
You are given that
f(x) = sin(x)
f(x) = sin(x)
f ( x ) = f ( 0 ) + f #( 0 ) ( x ” 0 ) + f ##( 0 ) ( x ” 0 ) 2 + f ###( 0 ) ( x ” 0 ) 3 + $ +
2! 3!
f(x) = f(0) + f#(0)x + f##(0) x2 + f###(0) x3 + $+ 2! 3!
d2f (x = 0) = ” sin(0) = 0 dx2 3
d f(x=0)=”cos(0)=”1 dx3
sin(0) = 0
df (x = 0) = cos(0) = 1
dx
f(x)=x”1×3+ 1 x5″ 1 x7+…… 6 120 5040
f(x)=x”1×3+ 1 x5″ 1 x7+…… 6 120 5040
Therefore for this example
P1(x)=x 1 3 P3(x) = x ” 6 x
P5(x)=x”1×3+ 1 x5 6 120
P7(x)=x”1×3+ 1 x5″ 1 x7 6 120 5040
x0
f(x) = sin(x)
“1×3+ 1 x5″ 1 x7 6 120 5040
P(x) = x 1
x0
f(x) = sin(x)
P(x) = x ” 1 x3
+ 1 x5″ 1 x7 120 5040
3
6
x0
f(x) = sin(x)
P(x)=x”1×3+ 1 x5
” 1 x7 5040
5
6 120
x0
f(x) = sin(x)
P(x)=x”1×3+ 1 x5″ 1 x7
7
6 120 5040
x0
f(x) = sin(x)
End of Example L01.1
L1.5
Mean Value Theorem (Page 5 of Book)
Mean Value Theorem
Recall Taylor’s Theorem
f(x) = PN(x) + RN(x) PN(x) = !N f (k)(x0) (x ” x0)k
RN(x) = f (N+1)(!(x)) (x ” x0)N+1 (N+1)!
k=0 k!
Let’s truncate the series at N=0
f(x) = f(x0) + f#(!(x))(x ” x0) Rearranging gives
P0(x) R0(x) x % !(x) % x0
f(x) ” f(x0) x”x0
= f#(!(x))
if f is a continuous function and differentiable between x
and x0, there exist a local gradient whose value is the
average gradient f(x) ” f(x0) x”x0
f(x)
Mean Value Theorem
f(xL) ” f(x0) xL ” x0
x0
x = xL
x
f(x) ” f(x0) x”x0
= f#(!(x)) x % !(x) % x0
f(x)
Mean Value Theorem
f(xL) ” f(x0) xL ” x0
x0
x = xL
x
f(x) ” f(x0) x”x0
= f#(!(x)) x % !(x) % x0
f(x)
Mean Value Theorem
f(xL) ” f(x0) xL ” x0
x0
x = xL
x
f(x) ” f(x0) x”x0
= f#(!(x)) x % !(x) % x0
f(x)
Mean Value Theorem
f(xL) ” f(x0) xL ” x0
x0 !(x)
x = xL
x
f(x) ” f(x0) x”x0
= f#(!(x)) x % !(x) % x0
f(x)
Mean Value Theorem
f(xL) ” f(x0) xL ” x0
x0 !(x)
x = xL
x
f(x) ” f(x0) x”x0
= f#(!(x)) x % !(x) % x0
L2.1 Root finding
A simple mathematical model: Skydiving Turtle
Drag=cv
Consider the forces acting on a turtle thrown out from a plane. According to Newton’s law:
F = m dv (2.1) dt
where
m= is the mass of the turtle, v = velocity of the turtle,
t = time
Nett force acting on the turtle
+ve
Gravity=mg
46
Drag=cv
Skydiving Turtle
+ve
Gravity=mg
For a turtle to free fall, nett force = gravitational weight of turtle + drag force on turtle due to air
F = mg ” cv
where c is the drag coefficient term, determined by the roughness of the skin of the turtle. Use this information and substitute into Eq. (2.1) will
give
mdv =mg”cv (2.2) dt
Solving Eq. (2.2) will give you the velocity of the turtle at various times, t. It turns out that Eq. (2.2) is simple enough to solve analytically (by hand). Let’s now find the solution. Divide
Eq. (2.2) by m gives:
dv =g” cv (2.3) dt 47 m
Skydiving Turtle
It is possible to solve Eq. (2.3) and show that
v(t) = gm (1 ” e” ct ) cm
(2.4)
if v=0 at t=0
gm/c
The function v(t) is shown on the left
t
48
v(t)
Skydiving Turtle
Given that the velocity of the turtle is governed
by Eq. (2.4), you wish to find the value of the drag coefficient, c,
such that a turtle of mass, m=5 kg, can attain a prescribed velocity, v=10 m/s, at a set period of time, t=9 s. For simplicity, use g=10 m/s2.
In the context of the problem mentioned above, m, v, and t are constant (parameters) of the problem. The only variable that we can adjust is c.
We cannot simply rearrange the equation to solve c as it shows up multiple times. To solve this problem, rewrite Eq. (2.4) as
v(t) = gm (1 ” e” ct ) f(c) = gm (1 ” e” ct ) ” v(t) cm cm
49
Skydiving Turtle
f(c) = gm (1 ” e” ct ) ” v(t) cm
sub m = 5, v = 10, t = 9, g = 10
f(c) = 10 & 5 (1 ” e” 9c ) ” 10
c5 f(c) = 50 (1 ” e” 9c ) ” 10
(2.5)
c5
So our task of solving the problem reduces to merely finding
the value of c, such that f(c) =0, for the given values of v, m and t.
In numerical analysis this is called finding the roots of an equation 50
Example L02.1: Write a MATLAB code to plot Eq. (2.5) and see how f(c) looks like
Lecture02M01.m
c=[0 0.1 0.2 0.3 0.4 0.5 0.6 …… 10] f(c)=50(1″e”9c)”10 0.1 0.1 0.1 0.1 0.1 0.1 c 5
(2.5)
c =0:0.1:10;
fc = 50./c.*(1-exp(-9.*c/5))-10;
figure
plot(c,fc,’b’,’linewidth’,2)
hold on
plot(c,zeros(size(c)),’k’,’linewidth’,2)
xlabel(‘c’)
ylabel(‘f(c)’)
axis([0 10 -10 10])
10 8 6 4 2 0 -2 -4 -6 -8 -10
0 1 2 3 4 5 6 7 8 9 10
c
f(c)
End of Example L02.1
Skydiving Turtle
10 8 6 4 2 0 -2 -4 -6 -8 -10
The graph on the left shows how f(c) (Eq. (2.5)) looks like
We need to find a value of c such that f(c)=0. In numerical analysis, this problem is called finding the roots of equation.
0 1 2 3 4 5 6 7 8 9 10
c
The rest of the lectures in this section will introduce different methods to obtain the roots of equation. I will illustrate each method by finding the root of Eq. (2.5).
53
f(c)
Graphical Method
One crude way of finding roots for an equation is to just plot the graph and visually inspect where the function evaluates to zero. For example, plot f(c) and find the value of c where f(c)=0.
10 8 6 4 2 0 -2 -4 -6 -8 -10
In the example on the left
the root at f(c) occur when
c is approximately 5 or 4.99382 to be more precise.
f(c) = 50 ( c
5 1″e”9c)”10
c≈5
0 1 2 3 4 5 6 7 8 9 10
c
54
f(c)
Graphical Method
As you can probably imagine, this method is not very practical because:-
• •
The main advantage of this method is that:-
• • •
You can use the MATLAB function fzero() to give a good accurate solution to f(c)=0
the accuracy is poor
difficult to repeat for a large number of different parameter values (eg. different m, g, and t)
you can see exactly how the function behaves.
how many roots there are for the equation.
the graphical method sometimes serve as a guide to finding the first guess for the root of the equation.
55
Example L02.2: The drawbacks of using the graphical method has been listed on the previous slide. You can use MATLAB to get a more accurate answer. The MATLAB function that you need is fzero(). Write a MATLAB code that uses the fzero() function to solve f(c)=0.
f(c) = 50 (1 ” e” 9c ) ” 10 = 0 c5
Lecture02M02.m
Output
Guess value of c when f(c)=0
fun = @(c) (50./c)*(1.0-exp(-9*c/5))-10; cr = fzero(fun,1.0)
10 8 6 4 2 0 -2 -4 -6 -8 -10
0 1 2 3 4 5 6 7 8 9 10
c
c≈5
What goes on inside fzero()? How does fzero() work? fzero() uses “Root Finding” algorithms/methods which will be described in more detail in the next section.
f(c)
End of Example L02.2
Root Finding Overview
Numerical algorithms for finding roots of equations
Bracketing methods
58
One point iteration
Open methods
Method of false position
Bisection method
Newton-Raphson
Secant method
Root Finding Overview
Bracketing Methods:
• • •
Open Methods:
• •
•
At least two guesses are required
Require that the guesses bracket the root of an equation More robust that open methods
Most of the time, only one initial guess is required
Do NOT require that the guesses bracket the root of the equation
More computationally efficient than bracketing methods but they do not always work…..may blow up !!
59
L2.2
Root finding:
Open Method-Fixed Point Iteration
60
Open Method
Open methods investigated in this subject
• • •
These methods require either only one initial guess or two initial guesses which do not have to bracket the actual root.
Unlike bracketing methods which always converge (i.e. the root for a particular equation is found), the open methods of root finding MAY NOT converge. However, if they do converge, they do so much more rapidly than bracketing methods.
Fixed-point iteration Newton-Raphson method Secant method
61
Fixed point iteration
To find the root of
f(x)=0,
(2.6)
rearrange the function so that x is on the left hand side (LHS) of the equation. i.e.
x=g(x).
We will rewrite the above equation as
xi+1=g(xi). (2.7)
Eq. (2.7) above provides us with a iterative formula to find the roots of Eq. (2.6). Note that the functional form of
Eq. (2.6) is not changed. Eq. (2.7) is just a rearrangement of Eq. (2.6).
New guess of x
62
Current guess of x
Fixed point iteration
Let’s say we want to find the root of f(x)= ex-10x=0,
we will rearrange it to get
x=(1/10)ex I.e. g(x)= ex and h(x)=x 1 x
xi+1 = 10e i
Iterate a few times until xi+1 is approximately equal to xi
(2.8)
Old guess of root to Eq. (2.8)
New guess of root to Eq. (2.8)
63
Example L02.3: Use the basic function of your calculator and complete the table below using the fixed point iteration scheme to find the root for
f(x) = ex ” 10x = 0 Start with the initial guess x1=1
f(x)=ex “10x=0 f(x)
We want to find xr
We rearrange to get
xr
Example L02.3: Use the basic function of your calculator and complete the table below using the fixed point iteration scheme to find the root for
f(x) = ex ” 10x = 0 Start with the initial guess x1=1
f(x)=ex “10x=0 f(x) We want to find xr
We rearrange to get
“x
x= e = g(x)
10
xr
xi+1 = exi = g(xi) 10
g(x) = ex 10
x
xr
Example L02.3: Use the basic function of your calculator and complete the table below using the fixed point iteration scheme to find the root for
f(x) = ex ” 10x = 0 Start with the initial guess x1=1
xi+1 = exi = g(xi) 10
0.2718
x
i
1
2
xi
1
0.2718
g(xi)
e1
0.2718
10
e0.2718
0.1312
10
3
0.1312
0.1140
4
0.1140
0.1121
5
0.1121
0.1119
6
0.1119
0.1118
0.1118
7
0.1118
8
0.1118
0.1118
g(x) = ex 10
0.1312
xr
Root of f(x)
End of Example L02.3
i
xi
g(xi)
1
1
0.2718
2
0.2718
0.1312
3
0.1312
0.1140
4
0.1140
0.1121
5
0.1121
0.1119
6
0.1119
0.1118
7
0.1118
0.1118
8
0.1118
0.1118
The numbers in the table above is very tedious to calculate if you just use a calculator Much easier to write a small MATLAB program to calculate.
L2.3 MATLAB: For Loops
MATLAB “for” loop is usually used when you want to execute MATLAB commands a fixed number of times. A “for” loop starts with a “for” and ends with an “end”
for i = 1:N
Command A
Command B
Command C
Command D
Command E
end
The MATLAB code above will execute command A, B, C, D, E N number of times.
Example L02.4: What is the final value of x for the MATLAB for loop given in the code below?
Lecture02M04.m
x=1.0 for i=1:5
x=x+1 end
Example L02.4: What is the final value of x for the MATLAB for loop given in the code below?
Lecture02M04.m
x=1.0 for i=1:5
x=x+1 end
x=1.0 for i=1:5
x=x+1 end
x is given the value of 1
Execute all the commands from “for” until the “end” statement incrementing i by 1 from 1 to 5 (i=1,2,3,4,5).
I
1
2
3
4
5
x
x=x+1 x=1+1 x=2
x=x+1 x=2+1 x=3
x=x+1 x=3+1 x=4
x=x+1 x=4+1 x=5
x=x+1 x=4+1 x=6
Final value of x
End of Example L02.4
L2.4
Root finding:
Back to Fixed Point Iteration
Example L02.5: Change the MATLAB code Lecture02M04.m to use the fixed point iteration scheme to find the root for
f(x) = ex ” 10x = 0
Using the one point iteration method”, we rearrange f(x) to get x= ex = g(x)
So we iterate using
10
xi+1 = exi = g(xi) 10
Lecture02M04.m
x=1.0 for i=1:5
x=x+1 end
Lecture02M05.m
Example L02.5: Change the MATLAB code Lecture02M04.m to use the fixed point iteration scheme to find the root for
f(x) = ex ” 10x = 0
Using the one point iteration method”, we rearranged f(x) to get x= ex = g(x)
So we iterate using
10
xi+1 = exi = g(xi) 10
Lecture02M04.m
x=1.0 for i=1:5
x=x+1 end
Lecture02M05.m
x=1.0
for i=1:5
x=(1./10.)*exp(x) x=x+1
end
Example L02.5: Change the MATLAB code Lecture02M04.m to use the fixed point iteration scheme to find the root for
f(x) = ex ” 10x = 0
Lecture02M05.m
x=1.0 for i=1:5
x=(1./10.)*exp(x) end
Output
f(x) = ex ” 10x
xr = 0.1119
End of Example L02.5
Example L02.6: Change the MATLAB code Lecture02M05.m to use the fixed point iteration scheme to find the root for
f(c) = 50 (1 ” e” 9c ) ” 10 = 0 c5
To use one point iteration scheme, need to rearrange so that you get an equation that looks like x=g(x) or c=g(c)
f(c) = 50 (1 ” e” 9c ) ” 10 c5
0 = 50 (1 ” e” 9c ) ” 10 c5
5
c = 5 (1 ” e” 9c ) = g(c)
So we iterate using
c =5(1″e”9ci) i+1 5
f (c)
g(c)
Example L02.6: Change the MATLAB code Lecture02M05.m to use the fixed point iteration scheme to find the root for
f(c) = 50 (1 ” e” 9c ) ” 10 = 0 c5
c =5(1″e”9ci) i+1 5
Lecture02M05.m
xi+1 =
Replace x with c
exi
10
Lecture02M06.m
c=1.0 for i=1:5
c=5*(1-exp(-9*c/5)) end
c =5(1″e”9ci) i+1 5
x=1.0 for i=1:5
x=(1./10.)*exp(x) end
Replace x with c and the iterative formula
Example L02.6: Change the MATLAB code Lecture02M05.m to use the fixed point iteration scheme to find the root for
f(c) = 50 (1 ” e” 9c ) ” 10 = 0 c5
Lecture02M06.m
f (c)
c=1.0 for i=1:5
c=5*(1-exp(-9*c/5)) end
Output
This number is very
similar to the output given by The MATLAB function fzero(). See output from Example L02.2
4.994
End of Example L02.6