相关代码 |
|
Sub ZBRAC(X1, X2, SUCCES) FACTOR = 1.6 NTRY = 50 If X1 = X2 Then Print "you have to guess an initial range" F1 = FUN(X1) F2 = FUN(X2) SUCCES = True For J = 1 To NTRY If F1 * F2 < 0 Then Exit Sub If Abs(F1) < Abs(F2) Then X1 = X1 + FACTOR * (X1 - X2) F1 = FUN(X1) Else X2 = X2 + FACTOR * (X2 - X1) F2 = FUN(X2) End If Next J SUCCES = False End Sub