Mathématiques en première générale – Algorithmes

Coefficient directeur des sécantes

Écrire la liste des coefficients directeurs des sécantes pour un pas donné.
def nombre_derive(f, a) :
    fa = f(a)
    def taux(h) :
        return (f(a + h) - fa) / h
    h = 1
    c = taux(h)
    h /= 2
    d = taux(h)
    while abs((d - c) / c) > 1e-15 :
        h /= 2
        c, d = d, taux(h)
        print(c)
    return d

print(nombre_derive(lambda x : x ** 2, 1))
print(nombre_derive(lambda x : 1 / x, 1))
from math import exp
print(nombre_derive(exp, 1))
print(exp(1))

2.5
2.25
2.125
2.0625
2.03125
2.015625
2.0078125
2.00390625
2.001953125
2.0009765625
2.00048828125
2.000244140625
2.0001220703125
2.00006103515625
2.000030517578125
2.0000152587890625
2.0000076293945312
2.0000038146972656
2.000001907348633
2.0000009536743164
2.000000476837158
2.000000238418579
2.0000001192092896
2.0000000596046448
2.0000000298023224
2.000000014901161
2.0
2.0
-0.6666666666666667
-0.7999999999999998
-0.8888888888888893
-0.9411764705882355
-0.9696969696969688
-0.9846153846153811
-0.9922480620155056
-0.9961089494163389
-0.9980506822612369
-0.9990243902439033
-0.9995119570521638
-0.9997559189650929
-0.9998779445868422
-0.9999389685690403
-0.9999694833531976
-0.9999847414437681
-0.9999923706636764
-0.9999961853027344
-0.9999980926513672
-0.9999990463256836
-0.9999995231628418
-0.9999997615814209
-0.9999998807907104
-0.9999999403953552
-0.9999999701976776
-0.9999999850988388
-1.0
-1.0
3.526814483758039
3.0882445160111853
2.8954801636718877
2.8050258514034567
2.7612008889018114
2.739629445827603
2.7289278227360683
2.723597892359635
2.720938129638398
2.7196095466729275
2.7189455795114554
2.7186136769778386
2.7184477459668415
2.7183647855272284
2.7183233065734385
2.7183025674312375
2.718292197911069
2.718287013238296
2.7182844209019095
2.7182831247337162
2.7182824769988656
2.718282153829932
2.7182819917798042
2.7182819098234177
2.7182818800210953
2.718281865119934
2.718281865119934
2.718281828459045
Lionel Avon