Tema7 - 7.6 Errata in Fig. 7.4; 6th line from the bottom of...

Info iconThis preview shows pages 1–6. 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
7.6 Errata in Fig. 7.4; 6th line from the bottom of the algorithm: the > should be changed to >= IF ( dx r < eps*x r OR iter >= maxit) EXIT Here is a VBA program to implement the Müller algorithm and solve Example 7.2. Option Explicit Sub TestMull() Dim maxit As Integer, iter As Integer Dim h As Single, xr As Single, eps As Single h = 0.1 xr = 5 eps = 0.001 maxit = 20 Call Muller(xr, h, eps, maxit, iter) End Sub Sub Muller(xr, h, eps, maxit, iter) Dim x0 As Single, x1 As Single, x2 As Single Dim h0 As Single, h1 As Single, d0 As Single, d1 As Single Dim a As Single, b As Single, c As Single Dim den As Single, rad As Single, dxr As Single x2 = xr x1 = xr + h * xr x0 = xr - h * xr Do iter = iter + 1 h0 = x1 - x0 h1 = x2 - x1 d0 = (f(x1) - f(x0)) / h0 d1 = (f(x2) - f(x1)) / h1 a = (d1 - d0) / (h1 + h0) b = a * h1 + d1 c = f(x2) rad = Sqr(b * b - 4 * a * c) If Abs(b + rad) > Abs(b - rad) Then den = b + rad Else den = b - rad End If dxr = -2 * c / den xr = x2 + dxr If Abs(dxr) < eps * xr Or iter >= maxit Then Exit Do x0 = x1 x1 = x2 x2 = xr Loop End Sub Function f(x) f = x ^ 3 - 13 * x - 12 End Function
Background image of page 4
7.7 The plot suggests a root at 1 -6 -4 -2 0 2 4 6 -1 0 1 2 Using an initial guess of 1.5 with h = 0.1 and eps = 0.001 yields the correct result of 1 in 4 iterations. 7.8 Here is a VBA program to implement the Bairstow algorithm and solve Example 7.3. Option Explicit Sub PolyRoot() Dim n As Integer, maxit As Integer, ier As Integer, i As Integer Dim a(10) As Single, re(10) As Single, im(10) As Single Dim r As Single, s As Single, es As Single n = 5 a(0) = 1.25: a(1) = -3.875: a(2) = 2.125: a(3) = 2.75: a(4) = -3.5: a(5) = 1 maxit = 20 es = 0.01 r = -1 s = -1 Call Bairstow(a(), n, es, r, s, maxit, re(), im(), ier) For i = 1 To n If im(i) >= 0 Then
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
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 / 14

Tema7 - 7.6 Errata in Fig. 7.4; 6th line from the bottom of...

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

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