MathGroup Archive 2006

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

Search the Archive

Using Map with a function of more than 1 argument

  • To: mathgroup at
  • Subject: [mg64241] Using Map with a function of more than 1 argument
  • From: "Matt" <anonmous69 at>
  • Date: Tue, 7 Feb 2006 03:36:29 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Hello Mathematica group,
  I'm starting down the path of trying to come up with my own complex
mapping function.  I'm aware of CartesianMap and PolarMap, but I've
been frustrated by those because of the lack of fine control I seem to
have (I say 'seem to have' because it might very well be the case that
I'm not aware of some of the finer points of these two functions).  The
fine control that is lacking, is for example, the fact that within
CartesianMap, if I want to specify different colors for the lines, I
can't really.  Let's say I went with the default of $Lines which is I
believe 25.  In order to have the lines draw in 25 different colours, I
believe I'd have to supply 25 color primitives to PlotStyle.  If I
supply less than 25, then the color primitives are recycled.  My first
plan of attack was to take the Graphics object that is output by
CartesianMap and try to manipulate the coloring primitive for each line
drawn based upon starting and ending points (i.e. within a 'Line', if
the first point's x value and the last point's x value were 'close',
than I knew I was dealing with a vertical line, or if the first point's
y value and the last points y value were 'close', then I knew I was
dealing with a horizontal line).  So, given the Graphics object output

graphicOne = CartesianMap[#1 & , {-1, 1}, {-1, 1}, Lines -> theLines,
    ImageSize -> {500, Automatic}, PlotStyle -> {RGBColor[1, 0, 0],
RGBColor[0, 0, 1]},
    PlotPoints -> thePlotPoints];

I was hoping that invoking something like

Position[graphicOne, ({RGBColor[__], {Line[_]}})?
   ((Print[Abs[First[#1[[2,1]]][[1,1]] - Last[#1[[2,1]]][[1,1]]]];
     Abs[First[#1[[2,1]]][[1,1]] - Last[#1[[2,1]]][[1,1]]] < 1.*^-9) &

would give me the positions of all of the horizontal lines, but then,
it seems that my lack of familiarity with Mathematica's rules for
working with accuracy and precision, led to results that made no sense
(i.e. it returned every Line as a match, instead of just the ones where
the x-coordinates were 'close').  Even worse than that, I realized that
my attempt was doomed to failure because even if I could get that
approach to work for a rectangular domain, it would not work once I had
applied a function that resulted in a graphic where the lines were
curved, twisted and traveling back over themselves.  It was at this
point that I decided to just work with single lines (i.e. graph a
single curve, then operate on each of the points contained within the
'Line' object and then graph the result in another graphic).

So, as a first step towards my goal, I thought, "OK, I need to write a
function that will be able to be used with Map on a list of points and
return the 'transformed' points as well as accept an arbitrary function
that will operate on each of the points."

Here is what I have thus far:

Clear[f, g];
f[z_, func_] := Module[{result}, result = func[Complex[Sequence @@ z]];
{Re[result], Im[result]}];
g[z_] := f[z, #1^2 & ];

Which, using 'g', I can use Map on a list of ordered pairs:

g /@ {{x,y}, {x,y}, {x,y}, {x,y}, etc.}

If I wanted to use Sin, I would redefine g as follows:

g[z_] := f[z, Sin];

then reapply to the list of ordered pairs.  So, I'm wondering if
there's a way to accomplish my task without the intermediary function
definition 'g'?  Also, if what I'm attempting is totally wrong, I'd
appreciate any pointers as to the correct 'path' as well.



  • Prev by Date: Re: Digital Image Processing: showing graylevel images in
  • Next by Date: Re: Re: Notebooks, packages, cells, and literate programming
  • Previous by thread: Re: Solve problems
  • Next by thread: Re: Using Map with a function of more than 1 argument