Tema6 - 6.16 Here is a VBA program to implement the...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6.16 Here is a VBA program to implement the Newton-Raphson algorithm and solve Example 6.3. Option Explicit Sub NewtRaph() Dim imax As Integer, iter As Integer Dim x0 As Single, es As Single, ea As Single x0 = 0# es = 0.01 imax = 20 End Sub Function df(x) df = -Exp(-x) - 1# End Function Function f(x) f = Exp(-x) - x End Function Function NewtR(x0, es, imax, iter, ea) Dim xr As Single, xrold As Single xr = x0 iter = 0 Do
Background image of page 6
xr = xr - f(xr) / df(xr) iter = iter + 1 If (xr <> 0) Then ea = Abs((xr - xrold) / xr) * 100 End If If ea < es Or iter >= imax Then Exit Do Loop NewtR = xr End Function It’s application yields a root of 0.5671433 after 4 iterations. The approximate error at this point is 2.1 × 10 - 5 %. 6.17 Here is a VBA program to implement the secant algorithm and solve Example 6.6. Option Explicit Sub SecMain() Dim imax As Integer, iter As Integer Dim x0 As Single, x1 As Single, xr As Single Dim es As Single, ea As Single x0 = 0 x1 = 1 es = 0.01 imax = 20 End Sub Function f(x) f = Exp(-x) - x End Function Function Secant(x0, x1, xr, es, imax, iter, ea) xr = x1 iter = 0 Do xr = x1 - f(x1) * (x0 - x1) / (f(x0) - f(x1)) iter = iter + 1 If (xr <> 0) Then ea = Abs((xr - x1) / xr) * 100 End If If ea < es Or iter >= imax Then Exit Do x0 = x1 x1 = xr Loop Secant = xr End Function It’s application yields a root of 0.5671433 after 4 iterations. The approximate error at this point is 4.77 × 10 - 3 %. 6.18
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/13/2012 for the course AEROSPACE 301 taught by Professor Pfchang during the Spring '12 term at Shandong University.

Page1 / 12

Tema6 - 6.16 Here is a VBA program to implement the...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online