# Homework 13, Least Squares Fitting (16 points)

Now that you are comfortable with using SGEFA and SGESL to solve a set of linear equations, its time to
do a real problem.

The file visc.tab contains viscosity data at selected temperatures. Each line contains first a
temperature and second the corresponding viscosity. We've already dealt with this as an exercise
in interpolation. This time I want you to generate a Least Squares approximation to the viscosity
data. Modify the program cubefit.f to approximate the viscosity as a cubic polynomial
(c0+c1*T+c2*T**2+ c3*T**3).

I want you to do three things to cubefit.f. First modify the subroutine "getdata" so that it asks the
user for the name of the file containing data pairs. Second, add a subroutine named "cubicfit" to
actually do the least squares fit. I recommend that you simply modify the subroutine quadfit. Finally,
create a separte file named "linpack.f" containing all of the LINPACK subroutines that you obtained for
Homework 13. Compile your program with the command "f77 cubefit.f linpack.f".

Leave the file **cubefit.f** in your homework directory.

### Grading will be as follows:

- Comments - 2 points
- Code to obtain the filename - 6 points
- Implementation of "cubicfit" - 8 points

I get the following answers when running my solution:

Fit to 3rd order polynomial has a mean error of 2.50719E-05
For the equation:
y = coef(0) + coef(1)*x + coef(2)*x**2 + coef(3)*x**3
coef(0) = 1.6147330E-02
coef(1) = -1.3551170E-04
coef(2) = 3.8962528E-07
coef(3) = -3.7671630E-10

**
**

Maintained by John Mahaffy : jhm@psu.edu