# Make plot of parametric function with piecewise components

How can I plot this curve in Mathematica:

\begin{align} x(t)&=\begin {cases} 2 (t-n+1) \: , \: t\in [n-1,n-1/2] \\ 2-2 (t-n+1) \: , \: t\in [n-1/2, n] \end {cases}\\ y(t)&=\begin {cases} 2 (\sqrt {2}t-n+1) \: , \: \sqrt {2} t\in [n-1,n-1/2] \\ 2-2 ( \sqrt {2} t-n+1) \: , \: \sqrt {2} t\in [n-1/2, n] \end {cases} \end{align}

with $n\in \mathbb{N}$

• You've seen Mod[] already? Commented Nov 26, 2015 at 23:00
• When posting code you should paste Mathematica code from your notebook as described here. Commented Nov 27, 2015 at 2:44

Since nobody followed up on my hint, here goes.

Noting that $y(t)=x(\sqrt 2 t)$, it suffices to define only $x(t)$.

A slight tweaking of the definition in the OP allows one to express the function in terms of Mod[]. However, it is actually more convenient to use QuotientRemainder[] instead, so I've employed it here:

x[t_] := Module[{nm, r}, {nm, r} = QuotientRemainder[t, 1];
Piecewise[{{2 r, nm <= t < nm + 1/2},
{2 - 2 r, nm + 1/2 <= t < nm + 1}}]]


However, some more thought, assisted by looking at a plot of the function, suggests a more compact expression:

x[t_] := (1 + TriangleWave[t - 1/4])/2


Here then is a plot of the desired parametric equation:

ParametricPlot[{x[t], x[Sqrt[2] t]}, {t, 0, 20}, PlotPoints -> 95]


I am not quite certain what you mean by

t ∈ [n - 1, n - 1/2]


and similar constructs in your question.

I am interpreting it to mean that for a particular n you will have two functions that cover the range {n-1, n-1/2} and {n-1/2, n-1}.

You can make plots for various values of n using Manipulate.

Manipulate[
Show[
ParametricPlot[{2 (t - n + 1), 2 (2 Sqrt[t] - n + 1)}, {t, n - 1,
n - 1/2}, PlotStyle -> Blue],
ParametricPlot[{2 - 2 (t - n + 1), 2 - 2 (2 Sqrt[t] - n + 1)}, {t,
n - 1/1, n}, PlotStyle -> Red],
PlotRange -> All,
AspectRatio -> 1/GoldenRatio
],
{{n, 1}, {1, 2, 3, 4, 5, 6}}
]


• I define the curve on [0,+\infty) Jack :) Commented Nov 27, 2015 at 6:36
• Sorry, I don't understand your problem. See if you can re-formulate it to make it crystal clear the problem that you are experiencing. Commented Nov 27, 2015 at 16:34