I have a x and y data, trying to find the the a and b coefficients using least square fit.
this is my code
My r transpose need to be in the format:
% define coordinates
x = [10 20 30 40 50 60 70];y = [0.765 0.995 1.248 1.524 1.695 2.132 2.463];plot(x,y,'*');axis([0 80 0 2]);hold onA1 = zeros(1);for i = 1:7 A1(i,1) = x(i)^2; A1(i,2) = x(i); A1(i,3) = 1.0;endr = inv(A1'*A1)*(A1'*y);t = (0:0.1:7);y1 = r(1)*t.^2 + r(2)*t + r(3);ploy(t,y1,'r');Error messageError using * Incorrect dimensions for matrix multiplication. Check that the number of columns inthe first matrix matches the number of rows in the second matrix. To performelementwise multiplication, use '.*'.
I did this: inv(A1'*A1)*A1'*y
But got an error message
Any possible fix is highly appreciated. Thanks
Best Answer