Tema13 - CHAPTER 13 13.13 Because of multiple local minima...

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

View Full Document Right Arrow Icon
CHAPTER 13
Background image of page 1

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

View Full Document Right 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 Document Right Arrow Icon
13.13 Because of multiple local minima and maxima, there is no really simple means to test whether a single maximum occurs within an interval without actually performing a search. However, if we assume that the function has one maximum and no minima within the interval, a check can be included. Here is a VBA program to implement the Golden section search algorithm for maximization and solve Example 13.1. Option Explicit Sub GoldMax() Dim ier As Integer Dim xlow As Double, xhigh As Double Dim xopt As Double, fopt As Double xlow = 0 xhigh = 4 Call GoldMx(xlow, xhigh, xopt, fopt, ier) If ier = 0 Then Else MsgBox "Does not appear to be maximum in [xl, xu]" End If End Sub Sub GoldMx(xlow, xhigh, xopt, fopt, ier) Dim iter As Integer, maxit As Integer, ea As Double, es As Double Dim xL As Double, xU As Double, d As Double, x1 As Double Dim x2 As Double, f1 As Double, f2 As Double Const R As Double = (5 ^ 0.5 - 1) / 2 ier = 0 maxit = 50 es = 0.001 xL = xlow xU = xhigh iter = 1 d = R * (xU - xL) x1 = xL + d x2 = xU - d f1 = f(x1) f2 = f(x2) If f1 > f2 Then xopt = x1 fopt = f1 Else xopt = x2 fopt = f2 End If If fopt > f(xL) And fopt > f(xU) Then Do d = R * d If f1 > f2 Then xL = x2 x2 = x1 x1 = xL + d f2 = f1 f1 = f(x1) Else xU = x1 x1 = x2 x2 = xU - d f1 = f2 f2 = f(x2) End If iter = iter + 1 If f1 > f2 Then
Background image of page 4
xopt = x1 fopt = f1 Else xopt = x2 fopt = f2 End If If xopt <> 0 Then ea = (1 - R) * Abs((xU - xL) / xopt) * 100 If ea <= es Or iter >= maxit Then Exit Do Loop Else ier = 1 End If End Sub Function f(x)
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

Tema13 - CHAPTER 13 13.13 Because of multiple local minima...

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