我的程序:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b, x1, x2, x3, h, h0, y1, y2, y3 As Double
x1 = Val(TextBox1.Text)
h0 = Val(TextBox2.Text)
h = h0
y1 = x1 * x1 - 6 * x1 + 9
x2 = x1 + h
y2 = x2 * x2 - 6 * x2 + 9
If y2 < y1 Then
h = 2 * h
x3 = x2 + h
y3 = x3 * x3 - 6 * x3 + 9
Do Until y2 < y3
x1 = x2
x2 = x3
y1 = y2
y2 = y3
h = 2 * h
x3 = x2 + h
y3 = x3 * x3 - 6 * x3 + 9
Loop
If h < 0 Then
a = x3
b = x1
Else
a = x1
b = x3
TextBox3.Text = a
TextBox4.Text = b
End If
Else
h = -h0
x3 = x1
y3 = y1
x1 = x2
x2 = x3
y1 = y2
y2 = y3
h = 2 * h
x3 = x2 + h
y3 = x3 * x3 - 6 * x3 + 9
Do Until y2 < y3
x1 = x2
x2 = x3
y1 = y2
y2 = y3
h = 2 * h
x3 = x2 + h
y3 = x3 * x3 - 6 * x3 + 9
Loop
If h < 0 Then
a = x3
b = x1
Else
a = x1
b = x3
TextBox3.Text = a
TextBox4.Text = b
End If
End If
End Sub
End Class