MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Interpolate in polar coordinates or cartesian

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112971] Re: Interpolate in polar coordinates or cartesian
  • From: "Ingolf Dahl" <ingolf.dahl at telia.com>
  • Date: Fri, 8 Oct 2010 04:50:27 -0400 (EDT)

Szymon,
Here is a somewhat delayed answer to the letter below concerning my "Obtuse"
package and NMaximize.
There are several issues to consider-

1. Your data set "Data" contains some doublet points with the same
coordinates x and y. This is not a problem for my "ObtuseAngle" method, but
if we want to compare with the "RBF" method, we obtain the message 

LinearSolve::nosol: Linear equation encountered that has no solution.

So I eliminate the point doublets with 

DataSorted = Sort[Data] //. {{a___, {b1_, b2_, b3_}, {b1_, b2_, b4_}, 
      c___} :> {a, {b1, b2, (b3 + b4)/2}, c}};

Then I restructure the data set with 

Data1 = Transpose[{DataSorted[[All, {1, 2}]], DataSorted[[All, 3]]}];

2. We should first look for the maximum in the data set, since this is a
hard and undisputable fact, while the NMaximize of an interpolation function
at the best could give a good guess.

Last[SortBy[Data1, Last]]

gives 

{{-0.135694, 0.135694}, 0.582}

3. Then we have the error message 

HierarchicalClustering`DistanceMatrix::amtd: -- Message text not found --

The default DistanceFunction in my package has used
HierarchicalClustering`DistanceMatrix to calculate distances between points.
This routine is defined in the kernel of Mathematica, in spite of its
context. Unfortunately it cannot handle cases when one of the points is
defined by symbolic variables. Therefore I have removed all references to
it, and replaced it with in-package routines. You might download the new
version of my package from http://www.familydahl.se/mathematica . I have
also redefined the default Distancefunction to be the distance squared,
instead of absolute value of distance squared, since we then obtain simpler
math for differentiation, and also in some cases obtain interpolation
functions that are analytic functions (e.g the RBF method with Gaussian
radial basis function).

4: I have also corrected a bug in how symbolic arguments to the
interpolation function were handled. I fell into the big If trap - if the
condition cannot be evaluated, If does not do anything (unless a fourth
argument is given) and does not defer evaluation until the condition can be
evaluated. And if I test if x != 0, this cannot be evaluated if x is
symbolic. But now If has been replaced by Piecewise in the critical
positions.

5. Interpolation with the method "ObtuseAngle" has InterpolationOrder set to
one as default, and then the function never get outside the maximum and
minimum of the function values in the data set. So in the best case,
NMaximize would give back the point found in point 2 above. If we set the
option InterpolationOrder to 2 or 3, or use the RBF method, one might find
non-trivial maxima.

6. However, NMaximize anyway has difficulties to find the correct maximum.
Either it keeps running endlessly, or it stops at some local maximum, below
0.582. The function sampled is just a small glitch in the plane of number
pairs, and NMaximize does not know where to look. It is sounder to use
FindMaximum with the maximum control point as starting point

test = Interpolation[Data1, Method -> "ObtuseAngle",  InterpolationOrder ->
2];
FindMaximum[test[{x, y}], {x, -0.135694}, {y, 0.135694}]

gives

{0.587718, {x -> -0.136951, y -> 0.136951}}

We might also test with the RBF method:

testRBF = Interpolation[Data1, Method -> "RBF"]
FindMaximum[testRBF[{x, y}], {x, -0.135694}, {y, 0.135694}]

gives

{0.731599, {x -> -0.141886, y -> 0.141358}}

Why this big difference? I tried to do a plot

Show[{Plot3D[testRBF[{x, y}], {x, -0.3, 0.3}, {y, -0.3, 0.3}, 
   PlotRange -> {-0.1, 0.8}, MeshFunctions -> {#3 &}, 
   Mesh -> {Range[-0.1, 0.8, 0.1]}, PlotPoints -> 30], 
  ListPointPlot3D[Data, 
   PlotRange -> {{-0.3, 0.3}, {-0.3, 0.3}, {-0.1, 0.6}}]}]

and the RBF interpolation function displays huge oscillations. This is
evidently a case when RBF interpolation straight out of the box fails.

Best regards

Ingolf Dahl

> -----Original Message-----
> From: Szymon Roziewski [mailto:szymon.roziewski at gmail.com]
> Sent: den 30 september 2010 10:50
> To: mathgroup at smc.vnet.net
> Subject: [mg112771] Re: Interpolate in polar coordinates or cartesian
> 
> Hello,
> Thank You very much for your solutions.
> I have such a problem namely, how I can find a maximum of interpolated
> function test?
> NMaximize doesn't work - it's surprised during computations.. or I do sth
> wrong...
> 
> 
> This is the output:
> 
> NMaximize[test0[{x, y}], {x, y}]
> 
> HierarchicalClustering`DistanceMatrix::amtd: -- Message text not found --
> ({{x,y},{0.0108186,0.0403757}}) >>
> 
> HierarchicalClustering`DistanceMatrix::amtd: -- Message text not found --
> ({{x,y},{0.0295571,0.0295571}}) >>
> 
> HierarchicalClustering`DistanceMatrix::amtd: -- Message text not found --
> ({{x,y},{0.0403757,0.0108186}}) >>
> 
> General::stop: Further output of
HierarchicalClustering`DistanceMatrix::amtd
> will be suppressed during this calculation. >>
> 
> 
> 
> 2010/9/29 u31815170 <ingolf.dahl at telia.com>
> 
> > Hi Szymon,
> > You might do this without my package with
> >
> > Show[{ListPlot3D[Data,
> >   PlotRange -> {{-0.3, 0.3}, {-0.3, 0.3}, {-0.1, 0.6}},
> >   MeshFunctions -> {#3 &}, Mesh -> {Range[-0.1, 0.6, 0.1]}],
> >  ListPointPlot3D[Data,
> >   PlotRange -> {{-0.3, 0.3}, {-0.3, 0.3}, {-0.1, 0.6}}]}]
> >
> > or with my package and with definitions below (shows more detail, takes
> > some
> > time)
> >
> > test == Interpolation[Data1, Method -> "ObtuseAngle",
> >  InterpolationOrder -> 2];
> > Show[{Plot3D[test[{x, y}], {x, -0.3, 0.3}, {y, -0.3, 0.3},
> >   PlotRange -> {-0.1, 0.6}, MeshFunctions -> {#3 &},
> >   Mesh -> {Range[-0.1, 0.6, 0.1]}, PlotPoints -> 30],
> >  ListPointPlot3D[Data,
> >   PlotRange -> {{-0.3, 0.3}, {-0.3, 0.3}, {-0.1, 0.6}}]}]
> >
> > This is sent from Outlook2007 as unformatted text
> > Best regards
> >
> > Ingolf Dahl
> > ingolf.dahl at telia.com
> >
> > -----Ursprungligt meddelande-----
> > Fr=E5n: Szymon Roziewski [mailto:szymon.roziewski at gmail.com]
> > Skickat: den 28 september 2010 12:06
> > Till: mathgroup at smc.vnet.net
> > =C4mne: [mg112728] Re: Interpolate in polar coordinates or cartesian
> >
> > hi there,
> > the interpolation works fine now,
> > but I wonder whether it is possible to make a contour lines on Plot3D
> > curve=
> >
> 
> 
> 
> --
> Z wyrazami szacunku,
> Szymon Roziewski
> 
> --0016e6db2d624aeb410491657e3d
> Content-Type: text/html; charset=ISO-8859-1
> Content-Transfer-Encoding: quoted-printable
> 
> Hello,<br>Thank You very much for your solutions.<br>I have such a problem
=
> namely, how I can find a maximum of interpolated function
test?<br>NMaximiz=
> e doesn&#39;t work - it&#39;s surprised during computations.. or I do sth
w=
> rong...<br>
> <br><br>This is the output:<br><br>NMaximize[test0[{x, y}], {x,
y}]<br><br>=
> HierarchicalClustering`DistanceMatrix::amtd: -- Message text not found --
(=
> {{x,y},{0.0108186,0.0403757}})
&gt;&gt;<br><br>HierarchicalClustering`Dista=
> nceMatrix::amtd: -- Message text not found --
({{x,y},{0.0295571,0.0295571}=
> }) &gt;&gt;<br>
> <br>HierarchicalClustering`DistanceMatrix::amtd: -- Message text not found
=
> -- ({{x,y},{0.0403757,0.0108186}}) &gt;&gt;<br><br>General::stop: Further
o=
> utput of HierarchicalClustering`DistanceMatrix::amtd will be suppressed
dur=
> ing this calculation. &gt;&gt;<br>
> <br><br><br><div class="gmail_quote">2010/9/29 u31815170 <span dir="ltr=
> ">&lt;<a href="mailto:ingolf.dahl at telia.com">ingolf.dahl at telia.com</a>&gt=
> ;</span><br><blockquote class="gmail_quote" style="border-left: 1px sol=
> id rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> <div class="im">Hi Szymon,<br>
> You might do this without my package with<br>
> <br>
> Show[{ListPlot3D[Data,<br>
>    PlotRange -&gt; {{-0.3, 0.3}, {-0.3, 0.3}, {-0.1, 0.6}},<br>
>    MeshFunctions -&gt; {#3 &amp;}, Mesh -&gt; {Range[-0.1, 0.6, 0.1]}],<b=
> r>
>   ListPointPlot3D[Data,<br>
>    PlotRange -&gt; {{-0.3, 0.3}, {-0.3, 0.3}, {-0.1, 0.6}}]}]<br>
> <br>
> or with my package and with definitions below (shows more detail, takes
som=
> e<br>
> time)<br>
> <br>
> test == Interpolation[Data1, Method -&gt; &quot;ObtuseAngle&quot;,<br>
>   InterpolationOrder -&gt; 2];<br>
> Show[{Plot3D[test[{x, y}], {x, -0.3, 0.3}, {y, -0.3, 0.3},<br>
>    PlotRange -&gt; {-0.1, 0.6}, MeshFunctions -&gt; {#3 &amp;},<br>
>    Mesh -&gt; {Range[-0.1, 0.6, 0.1]}, PlotPoints -&gt; 30],<br>
>   ListPointPlot3D[Data,<br>
>    PlotRange -&gt; {{-0.3, 0.3}, {-0.3, 0.3}, {-0.1, 0.6}}]}]<br>
> <br>
> This is sent from Outlook2007 as unformatted text<br>
> Best regards<br>
> <br>
> Ingolf Dahl<br>
> <a href="mailto:ingolf.dahl at telia.com">ingolf.dahl at telia.com</a><br>
> <br>
> -----Ursprungligt meddelande-----<br>
> </div><div class="im">Fr=E5n: Szymon Roziewski [mailto:<a href="mailt=
> o:szymon.roziewski at gmail.com">szymon.roziewski at gmail.com</a>]<br>
> </div><div class="im">Skickat: den 28 september 2010 12:06<br>
> Till: <a href="mailto:mathgroup at smc.vnet.net">mathgroup at smc.vnet.net</a><=
> br>
> </div>=C4mne: [mg112728] Re: Interpolate in polar coordinates or cartesia=
> n<br>
> <div class="im"><br>
> hi there,<br>
> the interpolation works fine now,<br>
> </div>but I wonder whether it is possible to make a contour lines on
Plot3D=
>  curve=<br>
> </blockquote></div><br><br clear="all"><br>-- <br>Z wyrazami szacunku,<br=
> >Szymon Roziewski<br>
> 
> --0016e6db2d624aeb410491657e3d--



  • Prev by Date: Re: Solve Question - 2 Non zero values
  • Next by Date: 3D on Ubuntu or Linux
  • Previous by thread: Re: Solve Question - 2 Non zero values
  • Next by thread: 3D on Ubuntu or Linux