python math.log对数

2021-01-06 17:46:54 浏览数 (1)

参考链接: Python中的numpy.log10

对数函数 

import math

import matplotlib.pyplot as plt

import numpy as np

if __name__ == '__main__':

    x = np.arange(0.05,3,0.05)

    y1 = [math.log(a,1.5) for a in x]

    plt.plot(x,y1,linewidth=2,color='red',label ='log1.5(x)')

    print(y1)

    plt.plot([1,1],[y1[0],y1[-1]],"r--",linewidth=2)

    y2 = [math.log(a, 2) for a in x]

    plt.plot(x, y2, linewidth=2, color='green', label='log2(x)')

    y3 = [math.log(a, 3) for a in x]

    plt.plot(x, y3, linewidth=2, color='blue', label='log3(x)')

    plt.legend(loc='lower right')

    plt.grid(True)

    plt.show() 

如果a的x次方=N(a>0,且a≠1), 

那么数x叫做以a为底N的对数,记作x=logaN,读作以a为底N的对数,其中a叫做对数的底数,N叫做真数

0 人点赞