Ordinary least-squares fit

  1. (6 points) Ordinary least-squares fit by QR-decomposition
    1. Implement a function which makes a least-squares fit 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 and the set of functions the linear combination of which should fit the data. The function must calculate the vector of the coefficients, ck .

    2. Fit the following data,

      x  =   0.100   0.145   0.211   0.307   0.447   0.649   0.944   1.372   1.995   2.900
      y  =  12.644   9.235   7.377   6.460   5.555   5.896   5.673   6.964   8.896  11.355
      dy =   0.858   0.359   0.505   0.403   0.683   0.605   0.856   0.351   1.083   1.002
      
      with the linear combination of functions {1/x, 1, x}.

    The fitting functions {fk(x)} can be implemented, e.g., as

  2. (3 points) Uncertainties of the fitting coefficients

  3. (1 points) Ordinary least-squares solution by thin singular-value decomposition

    1. Implement a function which makes a singular value decomposition of a (tall) matrix A by diagonalising ATA (with your implementation of the Jacobi eigenvalue algorithm), ATA=VDVT (where D is a diagonal matrix with eigenvalues of ATA and V is the matrix of the corresponding eigenvectors) and then using A=UΣVT where U=AVD-1/2 and Σ=D1/2.
    2. Implement a function which solves the linear least squares problem Ax=b using you implementation of singular-value decomposition.
    3. Implement a function which makes ordinary least-squares fit using your implementation of singular-value decomposition.
  4. (0 points) Extra

    Make up an interesting exercise here.