MATLAB: Dimensions of matrices being concatenated are not consistent.

consistent

Hello, how to fix it: Error using horzcat , Dimensions of matrices being concatenated are not consistent.
x1=[5.55;4.64;3.97;3.51;3.16];
x2=[57.38;39.52;29.33;22.93;18.62];
x3=[0.4;0.5;0.6;0.7;0.8];
Y=[2.01;2.42;2.81;3.16;3.53];
x=[1;1;1;1;1;1];
X=[x x1 x2 x3 x1.*x2 x1.*x3 x2.*x3 x1.^2 x2.^2 x3.^2];
C=X' ;
D=inv(C*X)
E=C*Y;
F = D*E

Best Answer

  • Your x vector is 6x1, while all other vectors are 5x1. Removing one element from that vector lets the code run without error:
    x1=[5.55;4.64;3.97;3.51;3.16];
    x2=[57.38;39.52;29.33;22.93;18.62];
    x3=[0.4;0.5;0.6;0.7;0.8];
    Y=[2.01;2.42;2.81;3.16;3.53];
    x=[1;1;1;1;1];
    X=[x x1 x2 x3 x1.*x2 x1.*x3 x2.*x3 x1.^2 x2.^2 x3.^2];
    C=X' ;
    D=inv(C*X)
    E=C*Y;
    F = D*E