python - I have a table of values that I want to integrate with other functions -
i have table of lot of data points, , want use them function multiply other functions , integrate. i'm not sure how go this. figured out how integrate table using simpsons rule, , tried use numpy.polynomial.plynomial.polyfit
best fit curve points values way off here have far:
import numpy np scipy import stats, integrate import matplotlib.pyplot plt scipy.integrate import quad import math s=5.670367e-8 a,b=np.array(np.loadtxt('cagn2.txt', skiprows=1, unpack=true)) #change file based on agn want. freq=np.arange(1e12,1e24,7e16) a1=a*2.41798926215e14 def f(nu): return nu**-1 #changed based on want def total(nu): return b * nu* f(nu) """ here want place function describing data points instead of 'b'""" e,err=quad(total,0,np.inf) #print(e) =integrate.simps(total,a1,even='first') #integrates table only, not want #print(i) c1,c2,c3,c4,c5=np.polynomial.polynomial.polyfit(a1,b,4) def y(x): return c1+ c2*x + c3*x**2+c4*x**3+ c5*x**4 n=y(freq) ax=plt.gca() ax.set_xscale('log') ax.set_yscale('log') plt.plot(a1,b) plt.plot(freq,n) plt.show()
this graph got, orange polyfit. graph of polyfit
as can see way off. know how can closer fit or how use table directly 'b' in total function? thanks
wiki
Comments
Post a Comment