Excercises 4

Interpolation

Interpolating functions

1. Interpolating a given function

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.  .. 6 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)).

2. Fitting to data

1. Read the file "data.dat" (can be downloaded from course homepage) 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.

3. 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 in same figure.

({{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`}})

Derivatives

1. Derivate (x^2) + 4  xwith respect to x

2. Derivate (x^4) + 3  x - sin(x) twice

3. Let the position of a moving body be given by the expression x(t)  =  40 - 5  t - 5  (t^2). What is the position, velocity and the acceleration at t = 2

4. Does Mathematica know the most common rules for taking derivatives? Find the derivative of

	a.	f(g(x))	(chain rule)
	
	b.	f(x) g(x)	(derivative of a product)
	
5. Let f(x, y) = (x^3) (y^4). Find the partial derivatives

	a. 	∂(f/∂)x, ∂(f/∂)y
	
	b.	(∂^2) (f/∂)(x^2), (∂^2) (f/∂)(y^2)
	
	c.	(∂^2) (f/(∂x ∂y)), (∂^2) (f/(∂y ∂x))