伽玛函数(Gamma函数),也叫欧拉第二积分,是阶乘函数在实数与复数上扩展的一类函数。该函数在分析学、概率论、偏微分方程和组合数学中有重要的应用。

import math
 
loss = 1e-30
def get_min_gamma(m, n):
    num = abs(n-m) / 4
    num1 = m + num * 0
    num2 = m + num * 1
    num3 = m + num * 2
    num4 = m + num * 3
    num5 = m + num * 4
    a1 = math.gamma(num1)
    a2 = math.gamma(num2)
    a3 = math.gamma(num3)
    a4 = math.gamma(num4)
    a5 = math.gamma(num5)
 
    print("当前段最小最大值:", (min(a1, a5), max(a1, a5)), "\t分别对应的x值", (num1, num5), "\t误差值", (abs(a1 - a5), abs(num1 -num5)))
    if abs(a1 - a5) <= loss and abs(a1 - a3) <= loss:
        return
    if a2 > a4:
        get_min_gamma(num3, num5)
    elif a2 < a4:
        get_min_gamma(num1, num3)
    else:
        get_min_gamma(num2, num4)
 
get_min_gamma(1, 2)
C:\Users\Administrator\Anaconda3\python.exe C:/Users/Administrator/Desktop/test.py
当前段最小最大值: (1.0, 1.0) 	分别对应的x值 (1.0, 2.0) 	误差值 (0.0, 1.0)
当前段最小最大值: (0.886226925452758, 1.0) 	分别对应的x值 (1.0, 1.5) 	误差值 (0.11377307454724195, 0.5)
当前段最小最大值: (0.886226925452758, 0.9064024770554773) 	分别对应的x值 (1.25, 1.5) 	误差值 (0.02017555160271922, 0.25)
当前段最小最大值: (0.886226925452758, 0.8889135691562254) 	分别对应的x值 (1.375, 1.5) 	误差值 (0.002686643703467384, 0.125)
当前段最小最大值: (0.8858546203723766, 0.886226925452758) 	分别对应的x值 (1.4375, 1.5) 	误差值 (0.00037230508038144094, 0.0625)
当前段最小最大值: (0.8856248564840745, 0.8858546203723766) 	分别对应的x值 (1.4375, 1.46875) 	误差值 (0.0002297638883020925, 0.03125)
当前段最小最大值: (0.8856248564840745, 0.8856342859692345) 	分别对应的x值 (1.453125, 1.46875) 	误差值 (9.429485160028506e-06, 0.015625)
当前段最小最大值: (0.8856034012131794, 0.8856248564840745) 	分别对应的x值 (1.4609375, 1.46875) 	误差值 (2.1455270895143208e-05, 0.0078125)
当前段最小最大值: (0.8856034012131794, 0.8856076096856554) 	分别对应的x值 (1.4609375, 1.46484375) 	误差值 (4.208472476063818e-06, 0.00390625)
当前段最小最大值: (0.8856034012131794, 0.8856038727761968) 	分别对应的x值 (1.4609375, 1.462890625) 	误差值 (4.715630174123575e-07, 0.001953125)
当前段最小最大值: (0.8856032284630198, 0.8856034012131794) 	分别对应的x值 (1.4609375, 1.4619140625) 	误差值 (1.7275015962159301e-07, 0.0009765625)
当前段最小最大值: (0.8856032126595705, 0.8856032284630198) 	分别对应的x值 (1.46142578125, 1.4619140625) 	误差值 (1.5803449215923138e-08, 0.00048828125)
当前段最小最大值: (0.8856031950223727, 0.8856032126595705) 	分别对应的x值 (1.46142578125, 1.461669921875) 	误差值 (1.763719781333606e-08, 0.000244140625)
当前段最小最大值: (0.8856031950223727, 0.8856031974555281) 	分别对应的x值 (1.4615478515625, 1.461669921875) 	误差值 (2.4331553438727838e-09, 0.0001220703125)
当前段最小最大值: (0.8856031946426789, 0.8856031950223727) 	分别对应的x值 (1.46160888671875, 1.461669921875) 	误差值 (3.7969383193114936e-10, 6.103515625e-05)
当前段最小最大值: (0.8856031944334692, 0.8856031946426789) 	分别对应的x值 (1.46160888671875, 1.461639404296875) 	误差值 (2.0920964960424726e-10, 3.0517578125e-05)
当前段最小最大值: (0.8856031944334692, 0.8856031944383083) 	分别对应的x值 (1.4616241455078125, 1.461639404296875) 	误差值 (4.839018075131207e-12, 1.52587890625e-05)
当前段最小最大值: (0.8856031944109473, 0.8856031944334692) 	分别对应的x值 (1.4616317749023438, 1.461639404296875) 	误差值 (2.2521984277545926e-11, 7.62939453125e-06)
当前段最小最大值: (0.8856031944109473, 0.8856031944159727) 	分别对应的x值 (1.4616317749023438, 1.4616355895996094) 	误差值 (5.025424520965771e-12, 3.814697265625e-06)
当前段最小最大值: (0.8856031944109473, 0.8856031944119014) 	分别对应的x值 (1.4616317749023438, 1.4616336822509766) 	误差值 (9.541256673628595e-13, 1.9073486328125e-06)
当前段最小最大值: (0.8856031944109473, 0.8856031944110347) 	分别对应的x值 (1.4616317749023438, 1.4616327285766602) 	误差值 (8.748557434046234e-14, 9.5367431640625e-07)
当前段最小最大值: (0.8856031944108936, 0.8856031944109473) 	分别对应的x值 (1.4616317749023438, 1.461632251739502) 	误差值 (5.362377208939506e-14, 4.76837158203125e-07)
当前段最小最大值: (0.8856031944108936, 0.8856031944108962) 	分别对应的x值 (1.4616320133209229, 1.461632251739502) 	误差值 (2.55351295663786e-15, 2.384185791015625e-07)
当前段最小最大值: (0.8856031944108885, 0.8856031944108936) 	分别对应的x值 (1.4616321325302124, 1.461632251739502) 	误差值 (5.10702591327572e-15, 1.1920928955078125e-07)
当前段最小最大值: (0.8856031944108885, 0.8856031944108896) 	分别对应的x值 (1.4616321325302124, 1.4616321921348572) 	误差值 (1.1102230246251565e-15, 5.960464477539063e-08)
当前段最小最大值: (0.8856031944108885, 0.8856031944108889) 	分别对应的x值 (1.4616321325302124, 1.4616321623325348) 	误差值 (3.3306690738754696e-16, 2.9802322387695312e-08)
当前段最小最大值: (0.8856031944108885, 0.8856031944108886) 	分别对应的x值 (1.4616321325302124, 1.4616321474313736) 	误差值 (1.1102230246251565e-16, 1.4901161193847656e-08)
当前段最小最大值: (0.8856031944108885, 0.8856031944108885) 	分别对应的x值 (1.4616321325302124, 1.461632139980793) 	误差值 (0.0, 7.450580596923828e-09)
当前段最小最大值: (0.8856031944108885, 0.8856031944108887) 	分别对应的x值 (1.4616321325302124, 1.4616321362555027) 	误差值 (2.220446049250313e-16, 3.725290298461914e-09)
当前段最小最大值: (0.8856031944108887, 0.8856031944108887) 	分别对应的x值 (1.4616321343928576, 1.4616321362555027) 	误差值 (0.0, 1.862645149230957e-09)
当前段最小最大值: (0.8856031944108887, 0.8856031944108889) 	分别对应的x值 (1.4616321343928576, 1.4616321353241801) 	误差值 (1.1102230246251565e-16, 9.313225746154785e-10)
当前段最小最大值: (0.8856031944108885, 0.8856031944108887) 	分别对应的x值 (1.4616321343928576, 1.4616321348585188) 	误差值 (2.220446049250313e-16, 4.656612873077393e-10)
当前段最小最大值: (0.8856031944108887, 0.8856031944108887) 	分别对应的x值 (1.4616321345092729, 1.4616321347421035) 	误差值 (0.0, 2.3283064365386963e-10)
 
Process finished with exit code 0