0
|
7203 Views
|
3 Replies
|
3 Total Likes
View groups...
Share

# Create and minimize a function f(x,y) using a list of data

Posted 11 years ago
 Hi!I'm new to Mathematica and need some help. I have a 3D surface (text file with x y z numbers). I'm able to read it with ReadList and plot itwith ListPlot3D, but I'd like to define the surface as a function:z=f(x,y)So I can then use NMinimize to search for local minina on the surface: NMinimize[z,{x,y}]I hope this makes sense and someone can help me.RegardsJ.
3 Replies
Sort By:
Posted 11 years ago
 Dear Gregory and Vitality, thanks a lot for your answer!I was able to do what I needed, and now I can test different optimization algorithms.RegardsJose
Posted 11 years ago
 Gregory, welcome to the site! It is really great to see your contribution here. I think your answer is spot on, I will extend it by giving an example.Create a list of multidimensional data:data = Flatten[Table[{{x, y}, LCM[x, y]}, {x, 4}, {y, 4}], 1]Create an approximate interpolating function:f = Interpolation[data]Plot the interpolating function:ContourPlot[f[x, y], {x, 1, 4}, {y, 1, 4}, ColorFunction -> "Rainbow"] Now find minimum In:= min = NMinimize[{f[x, y], 1 < x < 4 && 1 < y < 4}, {x, y}] Out= {-0.609654, {x -> 1.49554, y -> 1.49554}}  In:= pt = {x, y, min[]} /. min[] Out= {1.49554, 1.49554, -0.609654}  Show[ Plot3D[f[x, y], {x, 1, 4}, {y, 1, 4}, ColorFunction -> "Rainbow", PlotStyle -> Opacity[.8], MeshStyle -> Opacity[.5],MeshFunctions -> {Sqrt[#1^2 + #2^2 + #3^2] &}, Mesh -> 15],Graphics3D[{Red, PointSize[.08], Point[pt]}], PlotRange -> All] Posted 11 years ago
 Why don't you just interpolate your data using Interpolation function if you have a regular grid? Say, you've read your data in pts variable. ThenClear[x,y,z]z[x_, y_] = Interpolation[pts][x, y]Hopefully it'll help. Another way to find a minima is quite naive and approximate: to find a point with the smallest z:First@SortBy[pts, Last]Anyway, details depend on what data you have (regular or irregular grid, one or many minima, etc.)