MathGroup Archive 2008

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

Search the Archive

Re: Help to remove equivalent (redundant) solutions from

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91474] Re: [mg91455] Help to remove equivalent (redundant) solutions from
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 23 Aug 2008 01:41:07 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

Use SameTest option in Union

f[x_, y_] := Sin[x] Cos[y];

data = Flatten[Table[{{x, y}, f[x, y]},
    {x, 0, 2 Pi}, {y, 0, 2 Pi}], 1];

g = Interpolation[data, InterpolationOrder -> 4];

grad = D[g[x, y], {{x, y}, 1}];

Off[FindRoot::reged, InterpolatingFunction::dmval];

soln1 = Flatten[
   Table[FindRoot[grad,
     {{x, x0, 0, 2 Pi}, {y, y0, 0, 2 Pi}}],
    {x0, 0, 2 Pi}, {y0, 0, 2 Pi}], 1];

soln2 = Union[soln1, 
   SameTest ->
    (Chop[#1[[1, 2]] - #2[[1, 2]]] == 0 &&
       
       Chop[#1[[2, 2]] - #2[[2, 2]]] == 0 &)];

soln3 = Union[soln1, 
   SameTest ->
    (Rationalize[#1, 10^-10] ===
       
       Rationalize[#2, 10^-10] &)];

Length /@ {soln1, soln2, soln3}

{49,13,13}

soln2 == soln3

True


Bob Hanlon

---- Modeler <eabad at ulb.ac.be> wrote: 

=============
Assume I have the following code to find extrema of the 
function interpolating Sin[x]Cos[y] in the square  [0,2Pi]x[0,2Pi]:

f[x_, y_] := Sin[x ] Cos[y] 

data = Flatten[
Table[{{x, y}, f[x, y]}, {x, 0, 2 Pi}, {y, 0,
2 Pi}], 1]

g = Interpolation[data, InterpolationOrder -> 4] 

grad = D[g[x, y], {{x, y}, 1}]

Table[FindRoot[grad, {{x, x0, 0, 2 Pi}, {y, y0, 0, 2 Pi}}], {x0, 0,
2 Pi}, {y0, 0, 2 Pi}]

This will yield a list of the extrema, some of them are equivalent, but since the starting point of the algorithm is different every time one will get numerical errors that leads to tiny differences in the final values. Therefore, some entries of this list which ought to be equivalent are treated like distinct elements. Union[] or subsequent use of N[] with a given precision and Union[] won't help me get rid of the redundant elements. Any ideas how to bypass this problem?




  • Prev by Date: Re: Multifile search
  • Next by Date: Re: Help to remove equivalent (redundant) solutions from FindRoot[]
  • Previous by thread: Re: Re: Mathematica and F#
  • Next by thread: Re: Help to remove equivalent (redundant) solutions from