I tried to fit a line using 2D points. By using the SVD, I've successfully fit lines. However, in the one case, I failed to fit lines. Please, give me some advise and let me know the reasons.
% 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)]);
I've got succeed fit the line when I changed to 'V(:, 2)'. Why the second largest eigen value brings the best solution??