1
$\begingroup$

I have a transformation $T : [-1,1]^2 \to [-1,1]^2$ that is piecewise defined in the following way: \begin{align*} T(x,y) &= \big(a(x-1)+1,\:\left(b-cx\right)(y-1)+1\big) \quad \textrm{if } y > 0, \\ T(x,y) &= \big(d(x+1)-1, \: \left(e-fx \right)(y+1)-1\big) \quad \textrm{if } y \leq 0 \end{align*} for parameters $a,b,c,d,e,f \in \mathbb R$. I want to use Mathematica to help me visualize what the images of this function look like under repeated iteration.

I defined my function in Mathematica like so:

a=5/12; b=17/12; c=1/4; d=1/3; e=5/3; f=-1/6;
T[x_,y_] := {Piecewise[{{a(x-1)+1, y>0}, {d(x+1)-1, y<=0}}], 
Piecewise[{{(b-c*x)(y-1)+1, y>0}, {(e-f*x)(y+1)-1, y<=0}}]};

And then after writing T[0.4,0.1] and T[0.2, -0.4] to test the function, it returns as outputs {0.75, -0.185} and {-0.6, 0.02}. So this function appears to work.

Following in the footsteps of a (non-piecewise) example I was shown, I tried sketching the plot in the following way:

points=RandomReal[{-1,1},{5000,2}];
ListPlot[Map[T,points]]

which is written immediately below my lines in which I defined T[x_,y_]. I’m getting a sequence error message that all say:

Piecewise: The first argument {{-0.643301, False}, {0.422474}} of Piecewise is not a list of pairs.

with the numbers different between each error message. I wasn’t getting this error when I just directly evaluated T[x,y], only when I tried plotting it/evaluating a set of data.

As an experiment, I tried running the following script:

a=5/12; b=17/12; c=1/4; d=1/3; e=5/3; f=-1/6;
T[x_,y_] := {Piecewise[{{a(x-1)+1, y>0}, {d(x+1)-1, y<=0}}], 
Piecewise[{{(b-c*x)(y-1)+1, y>0}, {(e-f*x)(y+1)-1, y<=0}}]};
F[x_,y_] := (e-f*x)(y+1)-1; (*the y-coordinate function for T when y<=0*)
points = {{0.4, 0.1}};
T[0.4, 0.1]
F[0.4, 0.1]
List[Map[T, points]]

This results in the following outputs and error message, in the following order:

Out[196]= {0.75, -0.185}
Out[197]= 0.906667

Piecewise: The first argument {{-0.185, True}, {0.906667}} of Piecewise is not a list of pairs.

Out[198[= {{{0.75, Piecewise[{{(b-c0.4)(0.1-1)+1, 0.1>0}, {(e-f0.4)(0.1+1)-1}}]}}}

So it appears that the problem is with the second Piecewise used in defining T[x_,y_]. It looks like it’s completely ignoring the , y<=0 piece of it. Anyone have an idea of what’s going on here and how I can fix this?

$\endgroup$
1
  • 1
    $\begingroup$ It might simplify things a lot for you to define T so that it acts directly on points, e.g. T[{x_, y_}] := (* your original definition *). That should let you avoid Apply[], and also help with your follow-up question. $\endgroup$
    – J. M.'s torpor
    Jan 28 at 2:36
1
$\begingroup$

As used, Map will give T one List of two numbers as its argument, rather than two numbers. To do this as you intend, try this:

Map[Apply[T],points]
$\endgroup$
1
  • $\begingroup$ Thank you! This is exactly what I needed it to look like. As a follow-up, I’m having trouble iterating this transformation. I’ve described what I’m trying to do at this question: mathematica.stackexchange.com/questions/238931/… Any thoughts on what I should be trying to do here? $\endgroup$
    – D Ford
    Jan 28 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.