DefDbl A-Z
Dim crlf$, loge10, twopi
Function mform$(x, t$)
a$ = Format$(x, t$)
If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
mform$ = a$
End Function
Private Sub Form_Load()
ChDir "C:\Program Files (x86)\DevStudio\VB\projects\flooble"
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents
twopi = Atn(1) * 8
loge10 = Log(10)
l2014f = lxf(2014)
For j = 0 To 2014
term = l2014f - lxf(j) - lxf(2014 - j) + j * Log(0.2) / loge10
If term > Max Then Max = term: jmax = j
Next
Text1.Text = Text1.Text & jmax & Str(Max) & Str(10 ^ Max) & crlf
Text1.Text = Text1.Text & crlf
Text1.Text = Text1.Text & " done"
End Sub
Function lxf#(x#)
If x# < 171 Then
fact# = 1
If x# > 1 Then
For i = 2 To x#
fact# = fact# * i
Next
End If
lo# = log10#(fact#)
Else
lo# = log10#(x#) * (x# + 0.5)
lo# = lo# + (-x# + 1# / (12# * x#) - 1# / (360# * x# * x# * x#) + 1# / (1260# * x# * x# * x# * x# * x#)) / loge10#
lo# = lo# + log10#(twopi#) / 2#
End If
lxf# = lo#
End Function
Function log10(x)
log10 = Log(x) / loge10
End Function
finds j=335 has the maximum A(j), which is ~= 7.05447607762139 * 10^157.
The program uses logarithms to avoid overflow and the output is:
335 157.848464765072 7.05447607762139E+157
|
Posted by Charlie
on 2014-12-30 14:35:48 |