My is my matrix can't multiply with this vector

1 回表示 (過去 30 日間)
Khang Nguyen
Khang Nguyen 2020 年 11 月 22 日
編集済み: the cyclist 2020 年 11 月 22 日
I try to multiply a matrix with a vector to do the least square problem. Even thought my matrix and vector have the same dimention to multiply. MatLab say they don't have the same dimention. The erro happen in the last line
%create a cater plot
clear all;
%x = [20,30,40,50]
x = [-3,-1,1,2]
y=[8,23,28,34]
colum = [1,1,1,1]
plot(x,y,"O",'MarkerSize', 4);
matrixA1 =[]
%create a matrix
% first matrix
matrixA1 = [colum(:),x(:)]
%create the tranpose matrix
tranposeA = matrixA1.';
c = tranposeA*matrixA1
% power 1
final_matrix = [c tranposeA*y]

採用された回答

the cyclist
the cyclist 2020 年 11 月 22 日
編集済み: the cyclist 2020 年 11 月 22 日
Your variables tranposeA and y have sizes 2x4 and 1x4, respectively.
It is unclear to me whether you wanted a matrix multiplication or an element-wise multiplication. (If you don't know the difference, read about it in this documentation.)
You can stop your code an inspect your variable at any point by using the debugger.
Because I don't know what you want your code to do, I cannot offer specific advice on how to fix it. But the above information should help you fix it.
However, my best guess is that you intended x and y to be column vectors, not row vectors. If you try
% Notice that I did the transpose of these
x = [-3,-1,1,2].';
y=[8,23,28,34].';
then your code will run to completion. But, again, I don't know if this is really what you want.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by