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

MATLAB HELP NEEDED: Modify your solution to last week’s exercise (poly_curv_fit.

ID: 3589003 • Letter: M

Question

MATLAB HELP NEEDED:

Modify your solution to last week’s exercise (poly_curv_fit.m) by implementing left division rather than explicitly implementing the least-squares matrix solution.

-----------------poly_curv_fit.m BELOW-------------------

clear all
close all
clc


load noisy_poly.mat;
n = length(y);
x = 1:1:n;
PolyOrder=3;
p = polyfit(x,y,PolyOrder);
f = polyval(p,x);
figure,
plot(x,y,'.',x,f,'-');
xlabel('---- X --->');
ylabel('---- Y --->');
str = strcat('Plot between noisy-poly.mat and X at Poly Order = ',num2str(PolyOrder));
title(str);

Explanation / Answer

clc;

clear all;

close all;

x=[2.81 16.00 8.52 11.95 17.53 6.37 2.98 4.31 19.20 14.63 11.14 14.83 17.50 8.70];

y=[1.984 7.012 3.954 5.624 7.809 3.767 2.436 2.360 7.756 5.912 5.442 5.912 7.894 4.523];

n=2;% Quadratic regression

A=polyfit(x,y,n); %fit a n order polynomial

% A will be a vector of the coefficients for :

% a0+a1*x+a2*x^2+.............+an*x^n

Mn=min(x);

Mx=max(x);

xx=[Mn-1:(Mx-Mn)/100:Mx+1];

yy=polyval(A,xx);% generates expected values for each value of xx

figure;plot(x,y,'*',xx,yy,'r'); hold on

legend('Original Data Points','Quadratic Prediction');

OUTPUT:

A =
-0.0006 0.3734 1.0942
>>