## Non-Linear function estimation

For due dates see the calendar web page. For hand in details the lab main page.

### Objective

To practice the use and implementation of overdetermined equation systems/model fitting (Heath Ch3, Ch7) though a practical application.

### Procedure

340 students are not required to do Exercise 3 (they can directly download the data).

### Exercise 1: Polynomial interpolation/approximation (10 points)

First consider how to fit a polynomial to sin(x). (Note the similarity to the coefficient functions below). If you haven't done the readings, and tried the on-line polynomial calculator from the lectures page, consider doing this first. Then generate an example data vector for the sin function:

y = sin(0:0.5:m*pi)

Consider m = 0.5, 1, 2, 3. Then
• Write a function Y_new=polynomial_interp(X,Y,X_new,n) which fits a polynomial of degree n to Y=f(X), and returns the values of that polynomial for each element in the vector X_new. Use a polynomial basis of your choice (Monomial, Newton etc), set up the equation system and solve using matlab A\b. Note: if length(X) > n+1 then fit an approximate polynomial to the points in the least squares sense. (You can use the same A\b notation to solve the equation system for both cases) Now the polynomial doesn't necessarily go through the data points (does not interpolate in the strict sense), but is the best approximation in the least squares sense to the given data points.
• Plot the polynomial for X_new = (0:0.1:2^(1/n)*m*pi)'
• What degrees polynomial "fits" reasonably each of the cases m=0.5, 1, 2, 3 above?
• How does the polynomial compare with the true sin function?
• Inbetween sample points?
• Outside the samples interval? (note the "2^(1/n)" in X_new =(0:0.1:2^(1/n)*m*pi)' )
Plot the polynomial and sin in the same plot using e.g. solid (poly) and dotted (sin) lines. See "help plot" for how to structure the plot argument.

### Exercise 2: Fit a Polynomial along a brain tumor contour (10 points)

Fit a polynomial of order n along the contour of the brain tumor located in a brain MRI. The images are located in ~c340/web_docs/labs/labAssign2/brain_tumor.There are three images:tumor.jpg(real brain MRI image), tumor_groundtruth.jpg (Tumor labelled by radiologist) and tumorContour.jpg(Contour of the tumor labelled by radiologist). Find the set of points on tumor contour using following matlab code: