Tema14 - CHAPTER 14 14.8 Errata p 357 The initial value of the variable maxf must be set to some ridiculously small value before the iterations are

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

View Full Document Right Arrow Icon
CHAPTER 14
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
14.8 Errata: p. 357; The initial value of the variable maxf must be set to some ridiculously small value before the iterations are begun. Add the following line to the beginning of the VBA code: maxf = -999E9 The following code implements the random search algorithm in VBA: Option Explicit Sub RandSearch() Dim n As Long Dim xmin As Single, xmax As Single, ymin As Single, ymax As Single Dim maxf As Single, maxx As Single, maxy As Single xmin = -2 xmax = 2 ymin = -2 ymax = 2 n = InputBox("n=") Call RndSrch(n, xmin, xmax, ymin, ymax, maxy, maxx, maxf) MsgBox maxf MsgBox maxx MsgBox maxy End Sub Sub RndSrch(n, xmin, xmax, ymin, ymax, maxy, maxx, maxf) Dim j As Long Dim x As Single, y As Single, fn As Single maxf = -999E9 For j = 1 To n x = xmin + (xmax - xmin) * Rnd y = ymin + (ymax - ymin) * Rnd fn = f(x, y) If fn > maxf Then maxf = fn maxx = x maxy = y End If Next j End Sub Function f(x, y) f = 3.5 * x + 2 * y + x ^ 2 - x ^ 4 - 2 * x * y - y ^ 2 End Function 14.9 The following code implements the grid search algorithm in VBA:
Background image of page 4
Image of page 5
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 / 6

Tema14 - CHAPTER 14 14.8 Errata p 357 The initial value of the variable maxf must be set to some ridiculously small value before the iterations are

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

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