I am trying to come up with a program to impliment the secant method in Excel VBA. I have tried multiple ways of doing this. If statements, for-next, and do while loops. I believe the do while loops was the closest I got to completing it. For the program someone should be able to enter two initial conditions and their desired tolerence level. I have two main issues. The current code shown here will give an overflow error and not stop iterating the function. However; I believe that the do while condition should be bound>tolerence. I want it to iterate untile the bound is less than the tolerence and then msgbox that answer. Please help, I have only been doing excel for a week so I have alot to learn
Sub dwl()
xold = InputBox("Please input x-1 value")
x = InputBox("please input a x initial value")
tolerence = InputBox("Please input the tolerence,the difference between x initial and x-1, you wish to use")
e = 2.71828182845905
bound = Abs((x - xold))
Do While bound < tolerence
fxc = (3 * x) - (2 * x ^ 2) + (e ^ x) - 10
fxp = (3 * xold) - (2 * xold ^ 2) + (e ^ xold) - 10
nxt = x - ((fxc * (xold - x)) / (fxp - fxc))
xold = x
x = nxt
bound = Abs((x - xold))
Loop
MsgBox (nxt)
End Sub
Sub dwl()
xold = InputBox("Please input x-1 value")
x = InputBox("please input a x initial value")
tolerence = InputBox("Please input the tolerence,the difference between x initial and x-1, you wish to use")
e = 2.71828182845905
bound = Abs((x - xold))
Do While bound < tolerence
fxc = (3 * x) - (2 * x ^ 2) + (e ^ x) - 10
fxp = (3 * xold) - (2 * xold ^ 2) + (e ^ xold) - 10
nxt = x - ((fxc * (xold - x)) / (fxp - fxc))
xold = x
x = nxt
bound = Abs((x - xold))
Loop
MsgBox (nxt)
End Sub