What is the difference between different ways to do least square
이전 댓글 표시
Here I encounter this problem of using different ways to do least square. And I got different results (some are quite different). I want to know why. Basically, I tried to use different ways to compute ||Aθ-y||min. So I used these three methods.
theta_train_5k = ((A_train_5k'*A_train_5k)^-1)*A_train_5k'*y_train_5k;
% This is the result of least square
theta_train_5k_3 = A_train_5k\y_train_5k;
% This is also the result of least square
theta_train_5k_2 = lsqr(A_train_5k,y_train_5k);
% This is result of least square using lsqr
And I found different results.
theta_train_100 = ((A_train_100'*A_train_100)^-1)*A_train_100'*y_train_100;
theta_train_100_3 = A_train_100\y_train_100;
% This is also the result of least square for 100 data points
theta_train_100_2 = lsqr(A_train_100,y_train_100);
% This is result of least square using lsqr
For the above one, the result is even more strange. with theta_train_100 1000 to 100000 times larger than theta_train_3 and theta_train_2. So I was wondering when should I use which? Does it have something to do with the condition number or the singular value of the matrix?
Please help. Thank you in advance.
Variables are in the attachment
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!