Primer totalnih najmanjših kvadratov

% primer totalnih najmanjsih kvadratov


% podatki

x = [-2 -1 0 1 2];

y = [1.5 .2 .5 -2.3 -1.5];


% iscemo premico, ki se najbolje prilega

A = [1 1 1 1 1; x]'

b = y';


% stadardni NK

c1 = A\b


% totalni NK

[U,S,V] = svd([A b]);

c2 = -1/V(end,end)*V(1:end-1,end)



figure

plot(x,y,'ro')

hold on


xp = linspace(-4,4,5);

plot(xp,c1(1) + c1(2)*xp, 'g')

plot(xp,c2(1) + c2(2)*xp, 'b')

Zadnja sprememba: torek, 17 marec 2020, 18:43 PM