Skip to content

Latest commit

 

History

History
55 lines (33 loc) · 2.7 KB

README.md

File metadata and controls

55 lines (33 loc) · 2.7 KB

Linear least square fit and plotting with uncertainty

I. Introduction

This code is used as plot tool in my second year physics lab period. It can import data from a comma delimitated csv file and generate linear best fit line with residuals and uncertainties.

II. Theory

I used method of least squares[1] in a linear function of x and y,

y=mx+c

where m is the gradient and c is the y-intercept.

This is the rendered form of the equation. You can not edit this directly. Right click will give you the option to save the image, and in most browsers you can drag the image onto your desktop or another program.

with the uncertainty in the intercept and the gradient,

alpha c

alpha m

where

and is common uncertainty defined as

Ref:[1]I. G.Hughes and T. P.A.Hase, Measurements and their Uncertainties A practical guide to modern error analysis, 1st ed. Oxford: Oxford University Press, 2010, p. 58.

III. Demo

The demo data set was shown as file demo.csv with uncertainties on both x and y axis (No unit consideration).

X value Uncertainty of X Y value Uncertainty of Y
1 0.05 2 0.1
2 0.05 4 0.1
3 0.05 6 0.1
4 0.05 8 0.1
5 0.05 10 0.1
6 0.1 12 0.5
7 0.1 14 0.5
8 0.5 16 0.5
9 0.2 18 1
10 0.5 20 1

The plot can be found as plot.png , which is also the default output figure name.