(My problem is more complex, but let us formulate it through this example)
I am trying to find the best polynomial approximation to the following function
f[x_]:=Exp[x]^(1/2) + 2 - Exp[x] + x^5
through a polynomial (of an arbitrary degree) which would be non-increasing and "best approximation" means in the uniform distance on the interval [0, 1]
I have been trying to implement this with Mathematica, using NMinimize by just taking the code
g[x_]:=a x^2+b x + c
dis[a_, b_, c_] :=
Max[Abs[f[x]-g[x]]]
NMinimize[{dis[a,b,c], 0<=x<=1, 2xa + b <=0 },{a,b,c}]
The first part 0<=x<=1 is the restriction that I care only about for x in [0,1], the second (2xa + b <=0 ) is the restriction that polynomial is non-increasing.
However I get the error that
"The following constraints are not valid: {b+2 a x<=0, 0<=x<=1}. Constraints should be equalities, inequalities, or domain specifications involving the variables"
I mean I cannot use "FindFit" because there is no possibility to constrain the solution (i.e. the structure of the polynomial), nor that I am interested only in the domain $x\in[0,1]$
I would appreciate any thoughts on this, how to proceed...!
PS: In fact I would be quite interested to know how more generally one could incorporate constraints on the solution in terms of the fitting function (e.g. that it also integrates up to a given fixed number)
NMaximize[]
. Interpolate at the Chebyshev nodes, take the norm, and maximize over the coefficients. $\endgroup$