发布网友 发布时间:2022-04-25 12:36
共1个回答
热心网友 时间:2024-07-15 20:47
曲线图--- 代码---- from math import factorial import numpy as np import matplotlib.pyplot as plt #阶乘 def fact(n): return factorial(n) #Catalan公式 def cat_direct(n): return fact(2*n) // fact(n + 1) // fact(n) max = 20 nList = range(25) valList = [] print "Enter the limit for Catalan numbers to be printed: 10000000000" for i in nList: if i <= max: val = cat_direct(i) valList.append(val) print "C %s is:"%i, val else: print "C %s is:"%i, 10000000000 valList.append(10000000000) #---生成曲线 plt.plot(nList,valList, 'ro') plt.axis([0, 25, 0, 10000000000]) plt.xlabel("n") plt.ylabel("Catalan") plt.title("Cn+1 = 2*(2n+1)*Cn/(n+2)") plt.show()热心网友 时间:2024-07-15 20:47
曲线图--- 代码---- from math import factorial import numpy as np import matplotlib.pyplot as plt #阶乘 def fact(n): return factorial(n) #Catalan公式 def cat_direct(n): return fact(2*n) // fact(n + 1) // fact(n) max = 20 nList = range(25) valList = [] print "Enter the limit for Catalan numbers to be printed: 10000000000" for i in nList: if i <= max: val = cat_direct(i) valList.append(val) print "C %s is:"%i, val else: print "C %s is:"%i, 10000000000 valList.append(10000000000) #---生成曲线 plt.plot(nList,valList, 'ro') plt.axis([0, 25, 0, 10000000000]) plt.xlabel("n") plt.ylabel("Catalan") plt.title("Cn+1 = 2*(2n+1)*Cn/(n+2)") plt.show()