My previous topic in this area.
Problem in solving algorithm polynomial regression,least squares method in Octave
I decided not to change the main questions, but to create a new question for each problem.
This time, the problem is as follows.I worked with least square method in polynomial regression.
Differentiating this function with respect to the vector of parameters b and equating the derivatives to zero, we obtain the system of equations (in matrix form).This formula.
That is, if I want to express b from here, I need to do what I did.
b=X^{T}y/(X^{T}X)=> b=X'*y1/(X'*X)
Code:
#Generating random values โโof experimental data
x=0:0.1:5;
y=3*x+2;
y1=y+randn(size(y));
k=5;#Polynomial degree
X=[x' ones(length(x),1)];
b=X'*y1/(X'*X); Error: operator *: nonconformant arguments (op1 is 2x51, op2 is 1x51)\
Yes, the dimensions of the arrays X
and y1
do not coincide. Attached screenshots will show everything.In this screenshot variables X,y1 and X'(transposed).
Then I decided to select 1 column from the array X
and multiply it by y1
.
If you look at the screenshots, you will see that now the transposed X'
matches the y1
dimensions. That is, there should be no error, but it still exists.