Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am not the best at writing Matlab code, any help is appreciated... 2. A scienc

ID: 2986789 • Letter: I

Question

I am not the best at writing Matlab code, any help is appreciated...


2. A science experiment produced the following set of points:
(1, 3.0975) (2, 6.2785) (3, 9.5469) (4, 12.9575) (5, 15.9649) (6, 18.1576) Compute the 5th degree polynomial that interpolates (exactly goes through) the points using a Vandermonde matrix. Observe that this part of the question is NOT asking for a least squares fit. Now compute the best straight line fit using least squares. Do not set up a new matrix; extract the needed columns from the Vandermonde matrix. Turn in: a plot containing the 5th degree polynomial (in RED), the straight line (in GREEN) and the original points (as point-only plot with dots representing points) PLUS all necessary MATLAB commands to create these plots.
3. The linear fit of the data you created in the previous problem is only an approximation. Yet, a working scientist may prefer this fit to the exact 5th degree solution and not just for the simple reason that a linear function is mathematically more expedient to work with. Turn in: an explanation in one or two sentences.
4. Use the following points x = 0.1:0.1:1
y= [3.2641 2.8281 5.0391 3.9653 5.4878 6.3570 4.3012 10.8792 10.0212 11.7558] and compute the 9th degree polynomial that interpolates them, using the same technique as in problem 3. Plot the points, and the polynomial on the domain [0.1, 1]. What do you observe? Now create a best quadratic fit and add it to the plot. What is your conclusion? Turn in: a plot containing the 9th degree polynomial, the quadratic approximation and the original points, on the domain [0.1, 1], MATLAB commands, and a one-sentence conclusion.

Explanation / Answer

I am solving your first question. It will take some time..have patience


x0 = 1:1:6;
A = vander(x0);

y0 = [3.0975 6.2785 9.5469 12.9575 15.9649 18.1576];

C = inv(A)*y0';

a5 = C(1,1);
a4 = C(2,1);
a3 = C(3,1);
a2 = C(4,1);
a1 = C(5,1);
a0 = C(6,1);

f1 = @(x) (a5*x.^(5) + a4*x.^(4) + a3*x.^(3) + a2*x.^(2) + a1*x.^(1) + a0);

%Least sqare method
X2 = [x0.' ones(1,length(x0)).'];

m_c = inv(X2'*X2)*X2'*y0' ;
m = m_c(1,1);
c = m_c(2,1);
f_line = @(x) m*x + c;

x1 = -1:.5:7;
plot(x1,f_line(x1),'g','LineWidth',2.5);
hold all
plot(x1,f1(x1),'r','LineWidth',2.5);
hold all % hold plot and cycle line colors
plot(x0,f1(x0),'bo','LineWidth',2.5);
l = legend('Straight Line','5th order polynimial','data points')
set(l,'Location','NorthWest')
hold off
grid on % Turn on grid lines for this plot

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote