< />

Scipy kisara

Scipy

积分integration

import numpy as np
def main():
    from scipy.integrate import quad,dblquad,nquad#积分
    print(quad(lambda x:np.exp(-x),0,np.inf))
    print(dblquad(lambda t,x:np.exp(-x*t)/t**3,0,np.inf,lambda x:1,lambda x:np.inf))#二元积分
    print(quad(lambda x:x,0,1))#表明未知数:式子,下界,上界
    def f(x,y):
        return x*y
    def bound_y():
        return [0,0.5]
    def bound_x(y):
        return [0,1-2*y]
    print(nquad(f,[bound_x,bound_y]))#n元积分
    from scipy.optimize import root#优化器
    def fun(x):
        return x+2*np.cos(x)
    sol=root(fun,0.1)
    print("ROOT:",sol.x,sol.fun)
    pass
if __name__ == '__main__':
    main()

scipy插值

from pylab import *
import numpy as np
def main():
    x=np.linspace(0,1,10)#生成从0 到1 10个数
    y=np.sin(2*np.pi*x)
    from scipy.interpolate import interp1d
    li=interp1d(x,y,kind="cubic")
    x_new=np.linspace(0,1,50)
    y_new=li(x_new)
    figure()
    plot(x,y,"r")
    plot(x_new,y_new,"k")
    show()
    print(y_new)
    pass
if __name__ == '__main__':
    main()
kisarawechat kisaraalipay