Option Explicit
Dim arrX1(100) As Double
Dim arrX0(99) As Double
Dim arrSecantRootX(99) As Double
Public Function f(ByVal x As Double) As Double
If a.Text = "" Or b.Text = "" Or c.Text = "" Or d.Text = "" Or e1.Text = "" Or f1.Text = "" Or g.Text = "" Or h.Text = "" Or i1.Text = "" Or j.Text = "" Or k.Text = "" Or l.Text = "" Or m.Text = "" Or n1.Text = "" Or o.Text = "" Or sine.Text = "" Or cose.Text = "" Then
a.Text = 0
b.Text = 0
c.Text = 0
d.Text = 0
e1.Text = 0
f1.Text = 0
g.Text = 0
h.Text = 0
i1.Text = 0
j.Text = 0
k.Text = 0
l.Text = 0
m.Text = 0
n1.Text = 0
o.Text = 0
cose.Text = 0
sine.Text = 0
End If
f = (a.Text * x ^ 5) + (b.Text * x ^ 4) + (c.Text * x ^ 3) + (d.Text * x ^ 2) + (e1.Text * x) + f1.Text + (g.Text * (e ^ ((h.Text * x) + i1.Text))) + j.Text * (Cos(k.Text * x + l.Text)) ^ cose + m.Text * (Sin(n1.Text * x + o.Text)) ^ sine
End Function
Public Sub command1_click()
Dim X1 As Double
Dim X0 As Double
Dim fX0 As Double
Dim fX1 As Double
Dim secantrootx As Double
Dim n As Integer
Dim i As Integer
n = 0
X1 = int1.Text
X0 = int2.Text
arrX1(0) = X1
arrX0(0) = X0
arrSecantRootX(0) = secantrootx
Do
n = n + 1
If n = 0 Then
fX0 = f(X0)
Else
If n = 1 Then
fX1 = f(X1)
Else
secantrootx = X1 - ((fX1) * (X1 - X0) / (fX1 - fX0))
arrSecantRootX
= secantrootx
X0 = X1
arrX0
= X0
X1 = secantrootx
arrX1
= X1
Exit Do
End If
End If
Loop
For i = 0 To n
MsgBox (i & " " & arrSecantRootX(i) & "")
Next
End Sub