Ordinary least-squares fit

  1. (6 points)

    Implement a routine which makes a least-squares fit of a given data-set, {xi, yi, δyi | i=1...n}, with a linear combination of given functions, F(x) =∑ k=1..m ck fk(x).

    The subroutine must calculate the vector of the coefficients, ck, and the covariance matrix. The fitting functions {fk(x)} can be programmed, e.g., as

    Make up an interesting fitting example as an illustration of how your subroutine works.
  2. (3 points)
    Make up some interesting fits and check that the reported errors of the fitting coefficients are reasonable. For example,

  3. (1 point)
    Make up two experimental points with error bars, {xi, yi ± Δ yi | i=1,2}. Assume that the theoretical curve is a straight line. Make an ordinary least-squares fit of your experimental data with a linear function y(x)=a+bx. Make a plot of your results. On the plot illustrate the probable distribution of the variable y as function of x (in the assumption of normal distribution of yi, a, b if you need that).

    Hint: the variation of y with respect to variations of a and b as function of x is given as
    δy = δa + δb x.
    Therefore
    δy2 = δa2 + δb2 x2 +2δa δb x.
    For normally distributed a and b this translates into
    Δy2(x) = Δa2 + Δb2x2 + 2<δa δb>x
    where <δa δb> is the covariance.

  4. (0 points)

    Make up an interesting exercise here.