Question: How to optimize with an interpolated function

Hi,

I want to optimize a function f(g(e(x),x))  where g(x) is interpolated and e(x) is not known when the interpolation object is created. I found the intpolation Methods of Maple 2018 very helpful to quickly change the inpterpolation method.

Unfotunately the optimization fails when the interpolation object receives an expression as input.

It works if I just use x. Do you know my the first approach fails?

Is there maybe a way to convert the interpolation object to a piecewise function?

 

Thank you for your help
 

# Optimize with Interpolation Object


points :=  <<0.4000|  10.0000>,
            <0.7000|   10.0000>,
            <1.0000|   10.0000>,
            <0.3000|   30.0000>,
            <0.4000|   30.0000>,
            <0.5000|   30.0000>>;

Data := <0617,0767,0220,0444,0692,0789>*0.001;

intmethod := LinearInterpolation;

g := Interpolation[intmethod](points(1..-1,1),Data):

Matrix(6, 2, {(1, 1) = .4000, (1, 2) = 10.0000, (2, 1) = .7000, (2, 2) = 10.0000, (3, 1) = 1.0000, (3, 2) = 10.0000, (4, 1) = .3000, (4, 2) = 30.0000, (5, 1) = .4000, (5, 2) = 30.0000, (6, 1) = .5000, (6, 2) = 30.0000})

 

Vector[column](%id = 18446884324022199230)

 

LinearInterpolation

(1)

plot(g(x),x=0..1)

 

e := x/sqrt(2);

(1/2)*x*2^(1/2)

(2)

f := 5+g(e)*x^2

"5+(module() ... end module)(module() ... end module,1/2 x sqrt(2)) x^2"

(3)

f_simple := 5+g(x)*x^2

"f_simple:=5+[[["a linear interpolation object"],["with 6 points in 1-D"]]](x) x^2"

(4)

op_f := Optimization[Minimize](f(x),x=0 .. 1);

Error, (in Optimization:-NLPSolve) non-numeric result encountered

 

op_f_simple := Optimization[Minimize](f_simple(x),x=0 .. 1);

[HFloat(4.999979117244145), [x = HFloat(0.028901647183245588)]]

(5)

 

NULL


 

Download convert_interpolation_object.mw

 

 

Please Wait...