1

I am trying to implement polynomial regression using the least squares method. There was a problem while plotting the 3rd graph, it is not displayed. I think it's about the implementation of the formula y=ax+b. But in my case, in first I got experimental data values using inline functions polyfit and polyval.

x=0:0.1:5;
y=3*x+2;
y1=y+randn(size(y));
k=1;#Polynom
X1=0:0.01:10
B=polyfit(x,y1,k);
Y1=polyval(B,X1);

And after all, I am already using a linear model to solve the polynomial regression using the method of least squares.

Y2=Y1'*x+B'; -----this problem formula
subplot(3,2,3);
plot(x,Y1,'-b',X1,y1,'LineWidth');
title('y1=ax+b'); 
xlabel('x'); 
ylabel('y');
grid on;

As a result, no graph is drawn.

beginner
  • 183
  • 2
  • 12

1 Answers1

2

check size of the vector: x and Y1 are not same length, same for X1 and y1.

You probably want to plot as:

plot(x,y1,'-b',X1,Y1,'LineWidth', 1);
matzeri
  • 8,062
  • 2
  • 15
  • 16