Scilab Function
eng


polyfit

File content


function [p]=polyfit(x, y, n, s)
// return coefficient vector or poly if fourth string argument given
[lhs, rhs] = argn(0)
x = x(:); y = y(:)
m = length(x)
if length(y) <> m, error('x and y must have same length'), end
v = ones(m,n+1)
for i=2:n+1, v(:,i) = x.*v(:,i-1), end
p = (v\y)'
if rhs > 3, p = poly(p, s, 'coeff'), end
endfunction