Section courante

A propos

Section administrative du site

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 avec le PowerBASIC, il peut être intéressant d'effectuer les calculs par nous même:

DEF FNSquareRoot(X)
    LOCAL A,B,M,XN
    IF X=0.0 THEN FNSquareRoot=0.0:EXIT DEF
    M=1.0
    XN=X
    DO UNTIL XN<2.0  
      XN=0.25*XN
      M=2.0*M
    LOOP 
    DO UNTIL 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 WHILE B>=1.0E-15  
    FNSquareRoot=A*M
END DEF 

DEF FNLn(x)
    LOCAL negatif,fois,ajout,i
    negatif = 0
    fois = 1 
    ajout = 0 
    IF x<=0.0 THEN FNLn=0:EXIT DEF
    IF x<1.0 THEN negatif = 1:x = 1.0/x
    DO UNTIL x < 10.0 
       x = x / 10.0
       ajout = ajout + 2.302585092994046
    LOOP
    DO UNTIL x < 1.1
       x = FNSquareRoot(x)
       fois = fois * 2
    LOOP 
    DECR x 
    savx = x 
    i = 2
    xp = x*x
    quotient = (xp/i)
    dl = x-quotient
    DO UNTIL 1.0E-15>quotient
       INCR i 
       xp = xp * x
       dl = dl + (xp/i)
       INCR i
       xp = xp * x
       quotient = (xp/i)
       dl = dl - quotient
    LOOP
    dl = dl * fois
    dl = dl + ajout
    IF negatif=1 THEN dl = -dl
    FNLn=dl
END DEF
     
FOR I=0 TO 2.0 STEP 0.1
    PRINT "Ln("+STR$(I)+")="+STR$(FNLn(I)) 
NEXT

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 : Samedi, le 23 janvier 2016