Ordinary least-squares fit

Objective
Fit a linear combination of given functions, ∑ ckfk(x)|k=1..m, to a (measured) data set {xi, yi, δyi}i=1..n, where δyi are the uncertainties of the measurement (error-bars).
Tasks
  1. (6 points) Ordinary least-squares fit by QR-decomposition
    • You can use at your choice procedurial, object-oriented, or functional programming stile.
    • Make sure that your QR-decomposition routines work for tall matrices.
    • Implement a function that makes a least-squares fit—using your QR-decomposition routines—of a given data-set, {xi, yi, δyi}i=1...n , with a linear combination F(x)≐∑ k=1..m ck fk(x) of given functions fk(x)|k=1..m .
    • The parameters to the function should be the data to fit, {xi, yi, δyi}, and the set of functions, {fk}, the linear combination of which should fit the data. The function must calculate the vector of the coefficients, {ck}.
    • In 1902 [Rutherford and Soddy] measured the radioactivity of the (then not well explored) element ThX and obtained the following results,
      Time t (days)                     : 1   2   3  4  6  9    10   13   15
      Activity y of ThX (relative units): 117 100 88 72 53 29.5 25.2 15.2 11.1
      

      From this data they correctly deduced that radioactive decay follows exponentil law, y(t)=ae-λt (equation (1) in the article).

      Now, assume that the incertainty δy of the measurement was, say, about 5%,

      δy=y/20
      
      and fit the data with exponential function in the usual logarithmic way, ln(y)=ln(a)-λt. The uncertainty of the logarithm should be probably taken as δln(y)=δy/y.

      Plot the experimental data (with error-bars) and your best fit.

      From your fit find out the half-life time of ThX.

      ThX is today known as 224Ra – compare your result with the modern value.

  2. (3 points) Uncertainties of the fitting coefficients

    • Modify you least-squares fitting function such that it also calculates the covariance matrix and the uncertainties of the fitting coefficients.
    • Calculate the uncertainty of the half-life value for ThX from the given data.
    • Does it agree with the modern value within the estimated uncertainty?
  3. (1 points) Evaluation of the quality of the uncertainties on the fit coefficients

    • Plot your best fit,
      ∑ k=1..m ck fk(x),
      together with the fits where you change the fit coefficients by the estimated δc, that is,
      ∑ k=1..m (ck±δck) fk(x).