Page 461 - Chapra y Canale. Metodos Numericos para Ingenieros 5edición_Neat
P. 461
16.4 DISEÑO DE UNA BICICLETA DE MONTAÑA 437
FIGURA 16.11 Option Explicit
Macro para Excel escrito en
Function Golden(xlow, xhigh, R1, R2, R3, V)
Visual BASIC que determina
Dim iter As Integer, maxit As Integer, ea As Double, es As Double
un máximo con la búsqueda
Dim fx As Double, xL As Double, xU As Double, d As Double, x1 as Double
de la sección dorada.
Dim x2 As Double, f1 As Double, f2 As Double, xopt As Double
Const R As Double = (5 ^ 0.5 – 1) / 2
maxit = 50
es = 0.001
xL = xlow
xU = xhigh
iter = 1
d = R * (xU – xL)
x1 = xL + d
x2 = xU – d
f1 = f(x1, R1, R2, R3, V)
f2 = f(x2, R1, R2, R3, V)
If f1 > f2 Then
xopt = x1
fx = f1
Else
xopt = x2
fx = f2
End If
Do
d = R * d
If f1 > f2 Then
xL = x2
x2 = x1
x1 = xL + d
f2 = f1
f1 = f(x1, R1, R2, R3, V)
Else
xU = x1
x1 = x2
x2 = xU – d
f1 = f2
f2 = f(x2, R1, R2, R3, V)
End If
iter = iter + 1
If f1 > f2 Then
xopt = x1
fx =f1
Else
xopt = x2
fx = 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
Golden = xopt
End Function
Function f(Ra, R1, R2, R3, V)
f = (V * R3 * Ra / (R1 * (Ra + R2 + R3) + R3 * Ra + R3 * R2)) ^ 2 / Ra
End Function
6/12/06 13:56:29
Chapra-16.indd 437 6/12/06 13:56:29
Chapra-16.indd 437

