Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.8K Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Can interpolating functions be used in NMinimize constraints?

In[1]:= int = Interpolation[Table[{i, (i - 5)^2}, {i, 10}]]

Out[1]= InterpolatingFunction[{{1, 10}}, {
 5, 3, 0, {10}, {4}, 0, 0, 0, 0, Automatic, {}, {}, 
  False}, {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, {{16}, {9}, {4}, {1}, \
{0}, {1}, {4}, {9}, {16}, {25}}, {Automatic}]

In[5]:= NMinimize[{o, o == int[x]}, {x, 1, 10}]

During evaluation of In[5]:= InterpolatingFunction::dmval: Input value {0.652468} lies outside the range of data in the interpolating function. Extrapolation will be used.

During evaluation of In[5]:= NMinimize::bcons: The following constraints are not valid: {o==InterpolatingFunction[{{1,10}},{5,3,0,{10},{4},0,0,0,0,Automatic,{},{},False},{{1,2,3,4,5,6,7,8,9,10}},{{16},{9},{4},{1},{0},{1},{4},{9},{16},{25}},{Automatic}][x]}. Constraints should be equalities, inequalities, or domain specifications involving the variables.

Out[5]= NMinimize[{o, 
  o == InterpolatingFunction[{{1, 10}}, {
     5, 3, 0, {10}, {4}, 0, 0, 0, 0, Automatic, {}, {}, False}, {{1, 
     2, 3, 4, 5, 6, 7, 8, 9, 10}}, {{16}, {9}, {4}, {1}, {0}, {1}, {
     4}, {9}, {16}, {25}}, {Automatic}][x]}, {x, 1, 10}]
POSTED BY: Frank Kampas
5 Replies

Giving numbers after the variable in NMinimize gives a suggested search range, not bounds on the variables.

I think I've found a work-around

In[13]:= int = Interpolation[Table[{i, (i - 5)^2}, {i, 10}]];

In[14]:= NMinimize[{o, o == int[x]}, {o, x}] // Quiet

Out[14]= {\[Infinity], {o -> Indeterminate, x -> Indeterminate}}

In[15]:= NMinimize[{o, int[x] <= o <= int[x]}, {o, x}] // Quiet

Out[15]= {-7.45059*10^-9, {o -> -7.45059*10^-9, x -> 5.}}
POSTED BY: Frank Kampas
POSTED BY: Michael Rogers

That works for this example problem, but the problem I'm actually working with needs the Interpolation function in the constraints.

POSTED BY: Frank Kampas

Ok maybe so:

For 1D:

     int = Interpolation[Table[{i, (i - 5)^2}, {i, 10}]];

    {NMinimize[{x^4 - 3 x^2 - x, (x - 5)^2 < 8}, x] // Quiet, 
     NMinimize[{x^4 - 3 x^2 - x, int[x] < 8}, x] // Quiet, 
     NMinimize[{x^4 - 3 x^2 - x, int[x] < 8 && 1 < x < 10}, x] // Quiet}

     (* {{5.91934, {x -> 2.17157}}, {5.91934, {x -> 2.17157}}, {5.91934, {x ->2.17157}}}*)

For 2D:

    f = Interpolation[
      Flatten[Table[{{x, y}, x^2 + y^2 + x}, {x, -20, 20}, {y, -20, 20}], 
       1]](*Generating fake data*)
    NMinimize[{x^2 - (y - 1)^2, f[x, y] <= 4}, {x, y}]

   (* {-9.22366, {x -> -0.299019, y -> -2.05173}} *)

  NMinimize[{x^2 - (y - 1)^2, x^2 + y^2 + x <= 4}, {x, y}](* Check *)

    (* {-9.22366, {x -> -0.299019, y -> -2.05173}} *) (*OK*)
POSTED BY: Mariusz Iwaniuk

Try:

int = Interpolation[Table[{i, (i - 5)^2}, {i, 10}]];
NMinimize[{int[x], 1 < x < 10}, x]

(* {6.5524*10^-20, {x -> 5.}} *)

FindMinimum[{int[x], 1 < x < 10}, {x, 2}]

(* {0., {x -> 5.}} *)

Using FunctionInterpolation:

int2 = FunctionInterpolation[Cos[x], {x, 0, 6}];
{NMinimize[{int2[x], 0 < x < 6}, x], Plot[int2[x], {x, 0, 6}]}
POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard