Following the approach as given in the answer of Belisarius here I just wonder how one could incorporate some more sophisticated requirements on the approximating function.
Suppose the approximating model is as follows:
funcr[al_?NumericQ, be_?NumericQ, ga_?NumericQ, de_?NumericQ, k1_?NumericQ, k2_?NumericQ, x_?NumericQ] := (x^2 al + x be + k1) (x^2 ga + x de + k2) And there are two extra constraints on the approximating function:
- part
(x^2 ga + x de + k2)should integrate to 1 (on $x\in[0,1]$) and - part
(x^2 al + x be + k1)should be non-decreasing (on [0,1]).
I can easily incorporate the first requirement: just integrate this function and get the direct constraint: de/2 + ga/3 + k2 == 1 that I can introduce into NMinimize[..], so the final code is something like this:
piece[x_] := Piecewise[{{x^3, 1 >= x >= 0}, {1, x > 1}}, 0]; *"data"* funcr[al_?NumericQ, be_?NumericQ, ga_?NumericQ, de_?NumericQ, k1_?NumericQ, k2_?NumericQ, x_?NumericQ] := (x^2 al + x be + k1) (x^2 ga + x de + k2); norm[al_, be_, ga_, de_, k1_, k2_,x_] := (funcr[al, be, ga, de, k1, k2, x] - piece[x])^2 int[al_?NumericQ, be_?NumericQ, ga_?NumericQ, de_?NumericQ, k1_?NumericQ, k2_?NumericQ] := NIntegrate[norm[al, be, ga, de, k1, k2, x], {x, 0, 1}] nm = NMinimize[ {int[al, be, ga, de, k1, k2], de/2 + ga/3 + k2 == 1}, {al, be, ga, de, k1, k2}, Method -> "NelderMead", AccuracyGoal -> 3] But how can I introduce the condition on the first part, the requirement that (x^2 al + x be + k1) is non-decreasing on [0,1]? This involves $x$ now (namely derivative of (x^2 al + x be + k1) is positive) while NMinimize has no idea that $x$ exists.
I think this should be a part of the definition of the model, i.e. funcr but my attempts write it as a list of conditions all fail (neither makes sense to me.. nor works once in the program).
2*a1*x+beand insisting it be nonnegative onxin[0,1]reduces to checks at the endpoints since it is linear inx. So you have as constraintsbe>=0and2*a1+be>=0. $\endgroup$Intervalvalues then a sufficient condition is that the derivative thus eval'd be nonnegative (but this is not a necessary condition, and so could cause one to lose possible optimizing values). Requires some finesse, I think. $\endgroup$