|
Après avoir effectué des recherches dans de nombreux livres comme Scientific Pascal, Dictionnaire mathématique,..., je n'ai jamais trouvé aucun livre
fournissant une réponse correct du calcul du logarithme, outre le projet GNU (HaypoCALC).
Bien qu'il existe de nombreuses fonctions de logarithme dans le langage LotusScript, il peut être intéressant d'effectuer les calculs par nous même:
Function SquareRoot(X As Double) As Double
Dim A,B,M,XN As Double
If X=0.0Then
SquareRoot =0.0
Else
M=1.0
XN=X
Do While XN>=2.0
XN=0.25*XN
M=2.0*M
Loop
Do While XN<0.5
XN=4.0*XN
M=0.5*M
Loop
A=XN
B=1.0-XN
Do
A=A*(1.0+0.5*B)
B=0.25*(3.0+B)*B*B
Loop Until B<1.0E-15
SquareRoot=A*M
End If
End Function
Function Ln(Byval x As Double) As Double
Dim negatif As Integer
Dim fois As Double
Dim ajout As Double
Dim savx As Double
Dim i As Double
Dim xp As Double
Dim quotient As Double
Dim dl As Double
negatif = False
fois = 1
ajout = 0
If x <= 0.0 Then Ln = 0: Exit Function
If x < 1.0 Then
negatif = True
x = 1.0 / x
End If
While x >= 10.0
x = x / 10.0
ajout = ajout + 2.3025850929940459
Wend
While x >= 1.1
x = SquareRoot(x)
fois = fois * 2
Wend
x = x - 1
savx = x
i = 2
xp = x * x
quotient = (xp / i)
dl = x - quotient
While 0.000000000000001 < quotient
i = i + 1
xp = xp * x
dl = dl + (xp / i)
i = i + 1
xp = xp * x
quotient = (xp / i)
dl = dl - quotient
Wend
dl = dl * fois
dl = dl + ajout
If negatif Then dl = -dl
Ln= dl
End Function
Sub Main()
Dim i As Double
For i = 0 To 2.0 Step 0.1
Print "Ln(" &Str$(i) &")=" &Str$(Ln(i))
Next
End Sub
|
on obtiendra le résultat suivant:
Ln(0.0)=0.0
Ln(0.1)=-2.302585092994046
Ln(0.2)=-1.6094379124341056
Ln(0.3)=-1.2039728043259357
Ln(0.4)=-0.916290731874156
Ln(0.5)=-0.6931471805599471
Ln(0.6)=-0.5108256237659916
Ln(0.7)=-0.3566749439387316
Ln(0.8)=-0.22314355131420963
Ln(0.9)=-0.10536051565782642
Ln(1.0)=0.09531017980432469
Ln(1.2)=0.18232155679395437
Ln(1.3)=0.2623642644674894
Ln(1.4)=0.3364722366212136
Ln(1.5)=0.40546510810816594
Ln(1.6)=0.47000362924573785
Ln(1.7)=0.5306282510621684
Ln(1.8)=0.5877866649021186
Ln(1.9)=0.6418538861723971
|
Voir également
Science - Mathématique
|
|
| Dernière mise à jour: Vendredi, le 10 mars 2006 |