I want to fit the polynomial to noisy data, so that the approximated polynomial is always> = source data. For example:
x = linspace (-2, 6); y = (x-2).^2 + 1 + 2 * randn (size (x)); function ret = delta (P, x, y) yP = polyval (P, x); d = yP - y; d (d < 0) *= 1000; ret = sumsq (d); endfunction P0 = polyfit (x, y, 2); f = @(P) delta (P, x, y); [P, FVAL] = sqp (P0, f) xi = linspace (min(x), max(x), 100); yi = polyval (P, xi); plot(x, y, xi, yi); grid on

Is there a better way / method that also works with higher order polynomials?
An easy way would be to simply use polyfit and then calculate max(y-yi) and add this as an offset, but that would not be optimal ...
EDIT: I want to use GNU OCtave, but added "matlab" as a tag because the language and functions are similar.
EDIT: based on tvo response and real data:
x = [10 20 30 40 50 60 80 100]; y = [0.2372, 0.1312, 0.0936, 0.0805, 0.0614, 0.0512, 0.0554, 0.1407]; function ret = delta (P, x, y) ret = sumsq (polyval (P, x) - y); endfunction f = @(P) delta (P, x, y); h = @(P) polyval(P, x) - y; P0 = polyfit (x, y, 3); [P] = sqp (P0, f, [], h) xi = linspace (min(x), max(x)); yi = polyval (P0, xi); yio = polyval (P, xi); plot(x, y, xi, yi, ";initial guess;", xi, yio, ";optimized;"); grid on

but, as you can see, the optimized and rated poly has points <the original point, which is not allowed.