数值计算工具
scikit-numerical的Python项目详细描述
数值计算工具
此存储库包含数学数值计算工具,如数值积分和插值。当前实现包含:
使用高斯公式的数值积分
importnumpyasnpfromnumerical.integrationimportgaussdeff(x):returnnp.power(x[0],2)gauss.integrate(f,0.,1.)# 0.3333333
样条函数及其导数
importnumpyasnpfromnumericalimportsplinesimportmatplotlib.pyplotaspltx=np.arange(0,4.,0.05)y=splines.schoenberg(x)yd1=splines.schoenberg.deriv(x,order=1)# first derivativeyd2=splines.schoenberg.deriv(x,order=2)# second derivative# visualize resultsplt.plot(x,y)plt.plot(x,yd1)plt.plot(x,yd2)plt.show()
函数插值
importnumpyasnpfromnumericalimportinterpolateimportmatplotlib.pyplotaspltdeffun(x):return1-np.power(x[0]-0.5,2)grid=np.array([np.arange(0,1.0001,0.25)])values=fun(grid)itp_fun=interpolate(values,grid)x=np.arange(0.,1.00001,0.001).reshape(1,-1)y_intp=itp_fun(x)y_true=fun(x)plt.plot(x[0],y_intp)plt.plot(x[0],y_true)plt.show()