Re: 2D interpolation
- To: mathgroup at smc.vnet.net
- Subject: [mg72927] Re: 2D interpolation
- From: Peter Pein <petsie at dordos.net>
- Date: Thu, 25 Jan 2007 07:23:32 -0500 (EST)
- References: <ep7cv1$bl5$1@smc.vnet.net>
Jouvenot, Fabrice schrieb: > Hello, > > I am asking (again) for your knowledge to help me. > I try to have a 2 dimensional interpolation of points {x, y, f(x,y)}. > After some try, I wrote these lines (as an exemple of what I want to do) > that works : > ________________________________________ > > data = {{1, 1, -10}, {1, 2, 2}, {1, 3, 3}, {1, 4, 4}, {1, 5, 5}, {2, 1, > 2}, {2, 2, 4}, {2, 3, 6}, {2, 4, 8}, {2, 5, 10}, {3., 1, -9}, {3, 2, 6}, > {3, 3, 90}, {3, 4, 12}, {3, 5, 15}, {4, 1, 4}, {4, 2, 8}, {4, 3, 12}, > {4, 4, 16}, {4, 5, 20}, {5, 1, 5}, {5, 2, 10}, {5, 3, 15}, {5, 4, 20}, > {5, 5, 40.5}}; > > MatrixForm[data] > > test[x_, y_] := Interpolation[data][x, y]; > > test[1.5, 1.5] > > Plot[test[x, 1], {x, 1, 5}]; > > Plot[test[x, x], {x, 1, 5}]; > > Plot3D[test[x, y], {x, 1, 5}, {y, 1, 5}]; > > ________________________________________ > > > The problem is that when I want to use a point with a real x or y like > {1.23, 1.1, -10}, nothing works anymore. > I think that I miss something essential and fundamental, but I don'y > know why... > Thanks for your help, > Cheers, > > Fabrice. > Salut Fabrice, Interpolation works only on regular grids. There is a supplement written at university of freiburg, which can be downloaded at http://www.imtek.uni-freiburg.de/simulation/mathematica/IMSweb/. << "Imtek`Interpolation`" irregulardata = (#1 + Table[Random[]/10 - 1/20, {3}] & ) /@ {{1, 1, -10}, {1, 2, 2}, {1, 3, 3}, {1, 4, 4}, {1, 5, 5}, {2, 1, 2}, {2, 2, 4}, {2, 3, 6}, {2, 4, 8}, {2, 5, 10}, {3., 1, -9}, {3, 2, 6}, {3, 3, 90}, {3, 4, 12}, {3, 5, 15}, {4, 1, 4}, {4, 2, 8}, {4, 3, 12}, {4, 4, 16}, {4, 5, 20}, {5, 1, 5}, {5, 2, 10}, {5, 3, 15}, {5, 4, 20}, {5, 5, 40.5}}; sp = imsSpline[x, xi, 3]; func = imsUnstructuredInterpolation[irregulardata, sp]; func[1.5, 1.5] Plot[func[x, 1], {x, 1, 5}]; Plot[func[x, x], {x, 1, 5}]; Show[Block[{$DisplayFunction = #1 & }, {Plot3D[func[x, y], {x, 1, 5}, {y, 1, 5}], Graphics3D[{Red, PointSize[1/50], Point /@ ({0, 0, 0.05} + #1 & ) /@ irregulardata}]}]]; --> 0.7765956225038178 <Graphics omitted> Peter