30 lines
718 B
Python
Executable File
30 lines
718 B
Python
Executable File
from mathutils import *
|
|
from plotutils import *
|
|
|
|
|
|
x = [ 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0,18.0]
|
|
y = [ 30.0, 22.0, 12.0, 10.0, 11.0, 14.0, 21.0, 32.0]
|
|
v = [ 0.3, 0.8, 0.4, 0.3, 0.5, 0.4, 0.3, 0.2]
|
|
|
|
w = [ 1/ max(i,0.1) for i in v]
|
|
|
|
|
|
|
|
p=plot(None)[0]
|
|
p.setStyle(p.Style.ErrorY)
|
|
p.setLegendVisible(True)
|
|
s1 = LinePlotErrorSeries("Observed Data")
|
|
p.addSeries(s1)
|
|
for i in range(len(x)):\
|
|
s1.appendData(x[i], y[i], v[i])
|
|
|
|
|
|
pars_polynomial= fit_polynomial(y, x, 2, None, w)
|
|
function = PolynomialFunction(pars_polynomial)
|
|
plot_function(p, function, "Fit" , frange (min(x), max(x), 0.1), False)
|
|
|
|
print "(a0,a1,a2) = " , pars_polynomial
|
|
|
|
for xp in x:
|
|
print xp, poly(xp, pars_polynomial)
|