Scientific Programming Using Excel
for Beginners: Newton's Method
by
RIZAuddin bin Saian
Faculty of Computer & Mathematical Sciences
Universiti Teknologi MARA (Perlis)
Venue: Lab 1, UiTM Perlis
5 February 2016 (Friday)
3pm
Scientific Programming Using Excel for Beginners: Newton's Method
Problem
• We want to find the root for .
 xfy 
 xfy 
5/2/2016
2
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Objective
• To approximate the root for
using Newton’s method (Newton-Raphson
method)
– Perform Newton’s method by hand.
– Write a VBA code to perform the Newton’s
method.
 xfy 
5/2/2016
3
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Newton’s Method
 
 n
n
nn
xf
xf
xx
'
1 
5/2/2016
4
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Equation of tangent line
      
 
    
 
 
 
 n
n
nn
n
n
nn
nnnn
n
nnnnn
xf
xf
xx
xf
xf
xx
xxxfxf
xxf
xxxfxfxf
'
'
'0
interceptat the0
'
1
1
1
1
11










5/2/2016
5
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Initial Guess of x
Actual root
 xfy 
X
X
x0
(Initial guess)
5/2/2016
6
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Iteration 1
X
Tangent line at x0 = -1
 
 0
0
01
' xf
xf
xx 
X
 xfy 
x0x1
Actual root
(Initial guess)
5/2/2016
7
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Iteration 2
x1
Tangent line at x1
 
 1
1
12
' xf
xf
xx 
X X
 xfy 
x0
Actual root
(Initial guess)
5/2/2016
8
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Example: Find the root.
Actual root
X
x0 = -1
X
5/2/2016
9
http://www.rizauddin.com
  13
 xxxf
Scientific Programming Using Excel for Beginners: Newton's Method
Initial guess of x
  13
 xxxf 
  13'
1
2
3


xxf
xxxf
1
,ofguessInitial
0 x
x
 
 
13
1
'
2
3
1




x
xx
x
xf
xf
xxn
The estimated root,
5/2/2016
10
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Iteration 1
i x xn+1
0 - 1 -1.5
5/2/2016
11
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Iteration 2
i x xn+1
0 - 1 -1.5
1 -1.5 -1.347826087
5/2/2016
12
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Iteration 3
i x xn+1
0 - 1 -1.5
1 -1.5 -1.347826087
2 -1.347826087 -1.325200399
5/2/2016
13
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Iteration 4
i x xn+1
0 - 1 -1.5
1 -1.5 -1.347826087
2 -1.347826087 -1.325200399
3 -1.325200399 -1.324718174
5/2/2016
14
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Iteration 5
i x xn+1
0 - 1 -1.5
1 -1.5 -1.347826087
2 -1.347826087 -1.325200399
3 -1.325200399 -1.324718174
4 -1.324718174 -1.324717957
5/2/2016
15
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Iteration 6
i x xn+1
0 - 1 -1.5
1 -1.5 -1.347826087
2 -1.347826087 -1.325200399
3 -1.325200399 -1.324718174
4 -1.324718174 -1.324717957
5 -1.324717957 -1.324717957
5/2/2016
16
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Iteration 6
i x xn+1
0 - 1 -1.5
1 -1.5 -1.347826087
2 -1.347826087 -1.325200399
3 -1.325200399 -1.324718174
4 -1.324718174 -1.324717957
5 -1.324717957 -1.324717957
STOP!
5/2/2016
17
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Visual Basic for Application (VBA)
Press Alt key and hold. Then, press F11 together to open the VBA Editor.
5/2/2016
18
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Add new Module
5/2/2016
19
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Define a function
5/2/2016
20
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Exercise 1
• Define function Newton with parameter “x”
and return the estimation value for the root of
with x0=-1.  13
 xxxf
5/2/2016
21
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Exercise 1
• Define function Newton with parameter “x”
and return the estimation value for the root of
with x0=-1.  13
 xxxf
5/2/2016
22
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Loop
5/2/2016
23
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Exercise 2
• Modify the Newton function in Ex. 1 to use
loop to calculate the root using 4 iterations.
5/2/2016
24
http://www.rizauddin.com
Scientific Programming Using Excel for Beginners: Newton's Method
Exercise 2
• Modify the Newton function in Ex. 1 to use
loop to calculate the root using 4 iterations.
5/2/2016
25
http://www.rizauddin.com
THANK YOU
www.rizauddin.com
5/2/2016
26
http://www.rizauddin.com

Scientific Programming using Excel for Beginners: Newton's Method

  • 1.
    Scientific Programming UsingExcel for Beginners: Newton's Method by RIZAuddin bin Saian Faculty of Computer & Mathematical Sciences Universiti Teknologi MARA (Perlis) Venue: Lab 1, UiTM Perlis 5 February 2016 (Friday) 3pm
  • 2.
    Scientific Programming UsingExcel for Beginners: Newton's Method Problem • We want to find the root for .  xfy   xfy  5/2/2016 2 http://www.rizauddin.com
  • 3.
    Scientific Programming UsingExcel for Beginners: Newton's Method Objective • To approximate the root for using Newton’s method (Newton-Raphson method) – Perform Newton’s method by hand. – Write a VBA code to perform the Newton’s method.  xfy  5/2/2016 3 http://www.rizauddin.com
  • 4.
    Scientific Programming UsingExcel for Beginners: Newton's Method Newton’s Method    n n nn xf xf xx ' 1  5/2/2016 4 http://www.rizauddin.com
  • 5.
    Scientific Programming UsingExcel for Beginners: Newton's Method Equation of tangent line                      n n nn n n nn nnnn n nnnnn xf xf xx xf xf xx xxxfxf xxf xxxfxfxf ' ' '0 interceptat the0 ' 1 1 1 1 11           5/2/2016 5 http://www.rizauddin.com
  • 6.
    Scientific Programming UsingExcel for Beginners: Newton's Method Initial Guess of x Actual root  xfy  X X x0 (Initial guess) 5/2/2016 6 http://www.rizauddin.com
  • 7.
    Scientific Programming UsingExcel for Beginners: Newton's Method Iteration 1 X Tangent line at x0 = -1    0 0 01 ' xf xf xx  X  xfy  x0x1 Actual root (Initial guess) 5/2/2016 7 http://www.rizauddin.com
  • 8.
    Scientific Programming UsingExcel for Beginners: Newton's Method Iteration 2 x1 Tangent line at x1    1 1 12 ' xf xf xx  X X  xfy  x0 Actual root (Initial guess) 5/2/2016 8 http://www.rizauddin.com
  • 9.
    Scientific Programming UsingExcel for Beginners: Newton's Method Example: Find the root. Actual root X x0 = -1 X 5/2/2016 9 http://www.rizauddin.com   13  xxxf
  • 10.
    Scientific Programming UsingExcel for Beginners: Newton's Method Initial guess of x   13  xxxf    13' 1 2 3   xxf xxxf 1 ,ofguessInitial 0 x x     13 1 ' 2 3 1     x xx x xf xf xxn The estimated root, 5/2/2016 10 http://www.rizauddin.com
  • 11.
    Scientific Programming UsingExcel for Beginners: Newton's Method Iteration 1 i x xn+1 0 - 1 -1.5 5/2/2016 11 http://www.rizauddin.com
  • 12.
    Scientific Programming UsingExcel for Beginners: Newton's Method Iteration 2 i x xn+1 0 - 1 -1.5 1 -1.5 -1.347826087 5/2/2016 12 http://www.rizauddin.com
  • 13.
    Scientific Programming UsingExcel for Beginners: Newton's Method Iteration 3 i x xn+1 0 - 1 -1.5 1 -1.5 -1.347826087 2 -1.347826087 -1.325200399 5/2/2016 13 http://www.rizauddin.com
  • 14.
    Scientific Programming UsingExcel for Beginners: Newton's Method Iteration 4 i x xn+1 0 - 1 -1.5 1 -1.5 -1.347826087 2 -1.347826087 -1.325200399 3 -1.325200399 -1.324718174 5/2/2016 14 http://www.rizauddin.com
  • 15.
    Scientific Programming UsingExcel for Beginners: Newton's Method Iteration 5 i x xn+1 0 - 1 -1.5 1 -1.5 -1.347826087 2 -1.347826087 -1.325200399 3 -1.325200399 -1.324718174 4 -1.324718174 -1.324717957 5/2/2016 15 http://www.rizauddin.com
  • 16.
    Scientific Programming UsingExcel for Beginners: Newton's Method Iteration 6 i x xn+1 0 - 1 -1.5 1 -1.5 -1.347826087 2 -1.347826087 -1.325200399 3 -1.325200399 -1.324718174 4 -1.324718174 -1.324717957 5 -1.324717957 -1.324717957 5/2/2016 16 http://www.rizauddin.com
  • 17.
    Scientific Programming UsingExcel for Beginners: Newton's Method Iteration 6 i x xn+1 0 - 1 -1.5 1 -1.5 -1.347826087 2 -1.347826087 -1.325200399 3 -1.325200399 -1.324718174 4 -1.324718174 -1.324717957 5 -1.324717957 -1.324717957 STOP! 5/2/2016 17 http://www.rizauddin.com
  • 18.
    Scientific Programming UsingExcel for Beginners: Newton's Method Visual Basic for Application (VBA) Press Alt key and hold. Then, press F11 together to open the VBA Editor. 5/2/2016 18 http://www.rizauddin.com
  • 19.
    Scientific Programming UsingExcel for Beginners: Newton's Method Add new Module 5/2/2016 19 http://www.rizauddin.com
  • 20.
    Scientific Programming UsingExcel for Beginners: Newton's Method Define a function 5/2/2016 20 http://www.rizauddin.com
  • 21.
    Scientific Programming UsingExcel for Beginners: Newton's Method Exercise 1 • Define function Newton with parameter “x” and return the estimation value for the root of with x0=-1.  13  xxxf 5/2/2016 21 http://www.rizauddin.com
  • 22.
    Scientific Programming UsingExcel for Beginners: Newton's Method Exercise 1 • Define function Newton with parameter “x” and return the estimation value for the root of with x0=-1.  13  xxxf 5/2/2016 22 http://www.rizauddin.com
  • 23.
    Scientific Programming UsingExcel for Beginners: Newton's Method Loop 5/2/2016 23 http://www.rizauddin.com
  • 24.
    Scientific Programming UsingExcel for Beginners: Newton's Method Exercise 2 • Modify the Newton function in Ex. 1 to use loop to calculate the root using 4 iterations. 5/2/2016 24 http://www.rizauddin.com
  • 25.
    Scientific Programming UsingExcel for Beginners: Newton's Method Exercise 2 • Modify the Newton function in Ex. 1 to use loop to calculate the root using 4 iterations. 5/2/2016 25 http://www.rizauddin.com
  • 26.