how to find multiply variable in matrix multiplication

function least_square;
x=[1 2 3 4 5];
y=[4;2;5;3;7];
n=numel(x);
for i=1:n
A(i,1)=1;
A(i,2)=x(i);
A(i,3)=x(i).^2;
end
we have matrix A(5x3) and matrix y(5x1) let a matrix a(3x1) satisfy Aa=y so any function or method to find matrix a?

3 件のコメント

KSSV
KSSV 2018 年 5 月 29 日
You should initilaize your matrix A. Add this line before loop.
A = zeros(n,3) ;
Read about initialization
Stephen23
Stephen23 2018 年 5 月 29 日
@Vishal Rajpurohit: Note that the output matrix A should be preallocated:
Vishal Rajpurohit
Vishal Rajpurohit 2018 年 5 月 29 日
thankyou sir

サインインしてコメントする。

 採用された回答

KSSV
KSSV 2018 年 5 月 29 日

0 投票

a = A\y ;

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by