Matlab线拟合:奇异值分解(SVD)

时间:2016-12-20 14:17:07

标签: matlab svd

我尝试使用2D点拟合一条线。通过使用SVD,我成功地适应了线路。然而,在一个案例中,我没有适合行。请给我一些建议,让我知道原因。

% Data
X = [487,520.40,553.81,587.22,620.63,654.04,500,533.01,566.02,599.03,642,674.61,707.22,517,552.35,587.71,647,682.35,717.71,522,555.97,589.94,623.91,657.88];
Y = [521,558.20,595.40,632.60,669.80,707.00,533,570.55,608.10,645.66,695,732.90,770.80,564,599.35,634.71,694,729.35,764.71,562,598.68,635.37,672.06,708.75];

% b1*x + b2*y +b3 = 0
M = [X', Y', ones(size(X'))];
[~, ~, V] = svd(M);
B = V(:, 3);
b1 = B(1);
b2 = B(2);
b3 = B(3);

% Draw points
figure(111)
hold on;
plot(X, Y, 'ro');

% Draw line
minX = min(X);
maxX = max(X);
valY_minX = -(b3 + b1*minX) / b2;
valY_maxX = -(b3 + b1*maxX) / b2;
Pt1 = [minX;  valY_minX];
Pt2 = [maxX;  valY_maxX];
plot([Pt1(1), Pt2(1)], [Pt1(2), Pt2(2)]);

当我改为'V(:,2)'时,我已经成功了。为什么第二大特征值带来最佳解?

0 个答案:

没有答案