Friday, June 30, 2017

Python Plotting Tutorial -- Part 8

Fitting data with error bars

Suppose you have data \((x_i,y_i)\), with uncertainties \(\sigma_i\) in the y-values. Let
\[
U_n = \sum_i \frac{x_i^n}{\sigma^2_i},
\qquad
W_n = \sum_i   \frac{y_i  \, x_i^n}{\sigma^2_{i} } ,
\]
and let
\[
D = U_0 U_2 - U_1^2  .
\]
Then the best fit line is given by
\[
slope = \frac{U_0 W_1 - U_1 W_0}{D},
\qquad
intercept = \frac{U_2 W_0 - U_1 W_1}{D},
\]
with uncertainties
\[
\sigma_{slope}^2 = \frac{U_0}{D},
\qquad
\sigma_{intercept}^2 = \frac{U_2}{D}.
\]

As part of your homework, you will write a function which implements this method.

No comments:

Post a Comment