Problem solver call from vb6
It's been a while that Dana Delouis mailed me with the perfect
solution, but I forgot to put it on the board. But as people would
say "better late than never." :-)
Mail from Dana DeLouis:
Hi. If interested, here are just a couple of small ideas for your
code.
It seems to work find. However, it's not designed to be fancy to
catch the
errors when you take (-x)^(-2/3).
One idea here is to factor out a common term from the numerator and
denominator.
Sub TestIt()
Dim B2, B4, B13, B14
Dim Num, Den, de
Dim k As Double
Dim t As Double 'Temporary Variable
Dim N As Long ' Count of Loops
Dim C As Collection 'Check for Duplicates
Set C = New Collection
B2 = 0.28
B4 = 6.65
B13 = 4.25
B14 = 0.25
k = -(2 / 3)
de = 0.00001 'Or 10
On Error Resume Next
Do
N = N + 1
t = 2 * B14 * (de / (B13 - 2 * B14)) ^ k
Num = 2 * B2 - B4 + de + t
Den = 1 + (k * t) / de
de = de - (Num / Den)
C.Add de, CStr(de)
Debug.Print N; FormatNumber(de, 15)
Loop While Err.Number = 0 And N <= 30
End Sub
|