Excercise sheet 3

Interpolation

Tables

1. Make a table called DataA, that has as its elements ((Subscript[x, i]),  (Subscript[y, i])) the following table
	(Subscript[x, i])	(Subscript[y, i])
	1	4.0
	3	2.8
	4	2.5
	5	3.2
	6	3.9
	10	5.0
2. Make a table called DataB that has as its elements ((Subscript[x, i]),  ((Subscript[x, i])^2) + 10 (Subscript[x, i]) + 1), where (Subscript[x, i]) = 0, 1, 2,  ... , 5
3. Read a table from file "data.dat" and assign it to DataC.
3. Plot the tables DataA, DataB, and DataC
4. Add to the start of the table DataA the element (0, 6.0).
5. Add to the end of DataB the element (6,  0.0).
6. Insert to the third element of DataA the element (2,  3.4).

Interpolating functions

First

1. Make a table that has as its elements ((Subscript[x, i]),  (Subscript[x, i]) exp(-(Subscript[x, i]))), where (Subscript[x, i]) = 0, 1/2, 1, 3/2.  ..  Assign the symbol A to the table (A=Table[...])
2. Print out the contents of table A using the TableForm[...] function.
3. Make an interpolating polynomial to table A. 
4. Calculate the value of the polynomial at points x = 0,  1,  2.5 and compare the results with the corresponding values in table A
4. Plot the interpolating polynomial and the function x (e^(-x)) into same function.
5. Plot the difference of the interpolating polynomial and the function x (e^(-x)).

Second

1. Read the file "data.dat" into table A.
2. Make an interpolating function to table A
3. Plot the polynomial
5. Make an spline interpolating function to table A.
6. Plot the spline function.

Third -- An evil example - this shows that you have to be careful with the interpolating polynomial!

1. Make a table ((Subscript[x, i]),  (1/(25 ((Subscript[x, i])^2) + 1))), where (Subscript[x, i]) = -1, -0.8,  ... ,  0.8,  1.
2. Make an interpolating polynomial to the table
3. Make an interpolating function to the table
4. Plot the interpolating function and polynomial in the same figure. What do you see? Try increseasing / decresing the step length when making the table. You can also try making a spline fit to the table. Try plotting that in the same figure also.

Least squares fitting

Fit-command

1. Fit a second order polynomial to the data in the following table, and plot the data points and the fit.
({{-2, 2.84`}, {-1, 0.86`}, {0, 1.09`}, {1, 2.5100000000000002`}, {2, 7.17`}})

2. Fit the function a sin(x)  +  b cos(x)to the data in the following table, and plot the data points and the fit.
({{0, 1.04`}, {2, 0.44`}, {4, -1.51`}, {6, 0.6`}, {8, 0.78`}, {10, -1.45`}})

Regress-command

1. Fit a straight line a x + b to following data, and get the standard error in a and b
({{-1, -0.5`}, {0, 1.2000000000000002`}, {1, 2.8000000000000003`}, {2, 4.9`}})

2. Fit the function a + b (e^x) + 
        c x (e^x) to following data, and get the standard error for a,  b and c
({{0, 1.6`}, {0.5`, 3.8000000000000003`}, {1.`, 6.300000000000001`}, {1.5`, 12.700000000000001`}, {2.`, 22.900000000000002`}})