Use Matlab You are given the following data t 0 1 499 5 6 1

Use Matlab:

You are given the following data: t = [0 .1 .499 .5 .6 1.0 1.4 1.5 1.899 1.9 2.0] y = [0 .06 .17 .19 .21 .26 .29 .29 .30 .31 .31]

(a) Plot the data, using ”o” at the data points, then try a polynomial fit (polyfit) of the highest degree (y1) to interpolate this number of data points: What do you observe?

(b) Plot the polynomials of the highest order (y1) on the same plot.

(c) Give an explanation of this error? How you can plot the better curve (y2)? Plot y and y2 on the same graph.

Solution

Generally one would think that more data is better. Input the following data vectors: > t2 = [ 0 .1 .4 .5 .6 1.0 1.4 1.5 1.6 1.9 2.0] > y2 = [ 0 .06 .17 .19 .21 .26 .29 .29 .30 .31 .31] There are 11 data points, so a 10-th degree polynomial will fit the data. However, this does not give a good graph. Thus: A polynomial fit is better for small data sets. Finally, we note that each data point (xi , yi) gives an equation: pn(xi) = a0 + a1xi + a2x 2 i + · · · + anx n i = yi . The unknowns are the coefficients a0, . . . , an. This equation is linear in these unknowns, so determining a polynomial fit requires solving a linear system of equations. This makes polynomial fits quick to calculate since solving linear systems is what computers do best.

A way to plot this function in Matlab would be the following sequence of commands: > f = inline(’x.*sin(x.*y)’,’x’,’y’) > [X,Y] = meshgrid(0:.1:5,pi:.01*pi:2*pi); > Z = f(X,Y) > mesh(X,Y,Z) This will produce a 3-D plot that you can rotate by clicking on the rotate icon and then dragging with the mouse. Instead of the command mesh, you could use the command: > surf(X,Y,Z) The key command in this sequence is [X Y] = meshgrid(a:h:b,c:k:d), which produces matrices of x and y values in X and Y. Enter: > size(X) > size(Y) > size(Z) to see that each of these variables is a 51 × 51 matrix. To see the first few entries of X enter: > X(1:6,1:6) and to see the first few values of Y type: > Y(1:6,1:6)

Use Matlab: You are given the following data: t = [0 .1 .499 .5 .6 1.0 1.4 1.5 1.899 1.9 2.0] y = [0 .06 .17 .19 .21 .26 .29 .29 .30 .31 .31] (a) Plot the data,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site