blob: 89a4e0b793cf4f345b83c11356d9ed665c3363ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
function polynom = regress(x, y, degree)
assert(degree == 1 || degree == 2);
% doesnt work with old octave versions currently
%pot = @(x) x.^[degree:-1:0];
%M = reshape(cell2mat(arrayfun(pot, x(:)', 'UniformOutput', false)), degree+1, [])';
M = [];
if degree == 1
M = [ x.^1 x.^0 ];
end
if degree == 2
M = [ x.^2 x.^1 x.^0 ];
end
polynom = M \ y(:);
endfunction
|