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

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

CHAPTER 13

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

View Full Document

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

View Full Document
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
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)

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

View Full Document
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
Ask a homework question - tutors are online