scientific programming using excel for beginners: newton's method

26
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

Upload: rizauddin-saian

Post on 13-Apr-2017

183 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Scientific Programming using Excel for Beginners: Newton's Method

Scientific Programming Using Excel for Beginners: Newton's Method

byRIZAuddin bin Saian

Faculty of Computer & Mathematical SciencesUniversiti Teknologi MARA (Perlis)

Venue: Lab 1, UiTM Perlis5 February 2016 (Friday)

3pm

Page 2: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

2

Scientific Programming Using Excel for Beginners: Newton's Method

Problem

• We want to find the root for .

xfy

xfy

5/2/2016

Page 3: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

3

Scientific Programming Using Excel for Beginners: Newton's Method

Objective

• To approximate the root forusing 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

Page 4: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

4

Scientific Programming Using Excel for Beginners: Newton's Method

Newton’s Method

nn

nn xfxfxx

'1

5/2/2016

Page 5: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

5

Scientific Programming Using Excel for Beginners: Newton's Method

Equation of tangent line

nn

nn

n

nnn

nnnn

n

nnnnn

xfxfxx

xfxfxx

xxxfxfxxf

xxxfxfxf

'

'

'0intercept at the 0

'

1

1

1

1

11

5/2/2016

Page 6: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

6

Scientific Programming Using Excel for Beginners: Newton's Method

Initial Guess of x

Actual root

xfy

X

Xx0

(Initial guess) 5/2/2016

Page 7: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

7

Scientific Programming Using Excel for Beginners: Newton's Method

Iteration 1

X

Tangent line at x0 = -1

0

001 ' xf

xfxx

X

xfy

x0 x1

Actual root

(Initial guess) 5/2/2016

Page 8: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

8

Scientific Programming Using Excel for Beginners: Newton's Method

Iteration 2

x1

Tangent line at x1

1

112 ' xf

xfxx

X X

xfy

x0

Actual root

(Initial guess) 5/2/2016

Page 9: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

9

Scientific Programming Using Excel for Beginners: Newton's Method

Example: Find the root.

Actual root

X

x0 = -1X

5/2/2016

13 xxxf

Page 10: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

10

Scientific Programming Using Excel for Beginners: Newton's Method

Initial guess of x 13 xxxf

13'

12

3

xxf

xxxf

1, of guess Initial

0 xx

131

'

2

3

1

xxxx

xfxfxxn

The estimated root,

5/2/2016

Page 11: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

11

Scientific Programming Using Excel for Beginners: Newton's Method

Iteration 1i x xn+1

0 - 1 -1.5

5/2/2016

Page 12: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

12

Scientific Programming Using Excel for Beginners: Newton's Method

Iteration 2i x xn+1

0 - 1 -1.5

1 -1.5 -1.347826087

5/2/2016

Page 13: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

13

Scientific Programming Using Excel for Beginners: Newton's Method

Iteration 3i x xn+1

0 - 1 -1.5

1 -1.5 -1.347826087

2 -1.347826087 -1.325200399

5/2/2016

Page 14: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

14

Scientific Programming Using Excel for Beginners: Newton's Method

Iteration 4i 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

Page 15: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

15

Scientific Programming Using Excel for Beginners: Newton's Method

Iteration 5i 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

Page 16: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

16

Scientific Programming Using Excel for Beginners: Newton's Method

Iteration 6i 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

Page 17: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

17

Scientific Programming Using Excel for Beginners: Newton's Method

Iteration 6i 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

Page 18: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

18

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

Page 19: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

19

Scientific Programming Using Excel for Beginners: Newton's Method

Add new Module5/2/2016

Page 20: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

20

Scientific Programming Using Excel for Beginners: Newton's Method

Define a function5/2/2016

Page 21: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

21

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

Page 22: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

22

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

Page 23: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

23

Scientific Programming Using Excel for Beginners: Newton's Method

Loop5/2/2016

Page 24: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

24

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

Page 25: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

25

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

Page 26: Scientific Programming using Excel for Beginners: Newton's Method

http://ww

w.rizauddin.com

26

THANK YOUwww.rizauddin.com

5/2/2016