Linear Curve Fitting

Linear curve fitting, or simple linear regression, models the relationship between two variables by fitting a straight line through the data. It assumes the relationship follows:

y=mx+cy = mx + c

Here, mm is the slope of the line and cc is the y-intercept. The goal is to find the values of mm and cc that minimize the sum of the squared differences between the observed and predicted values.

Error Minimization

We use the method of least squares, minimizing:

S=i=1n(yi(mxi+c))2S = \sum_{i=1}^n (y_i - (mx_i + c))^2

Taking derivatives of SS with respect to mm and cc, and setting them to zero yields:

m=nxiyixiyinxi2(xi)2m = \frac{n\sum x_i y_i - \sum x_i \sum y_i}{n\sum x_i^2 - (\sum x_i)^2}
c=yimxinc = \frac{\sum y_i - m\sum x_i}{n}

Once mm and cc are calculated, the fitted liney=mx+cy = mx + c can be used to make predictions or interpret the relationship.