0

I am using Tikz to draw a simple figure with the absolute value function and a parabola joining two points. My code snippet is:

\begin{tikzpicture}
\draw (0,0) -- (2,2);
\draw (0,0) -- (-2,2);
\draw (-0.5,0.5) parabola (1,1);
\end{tikzpicture}

However, this draws a parabola connecting (-0.5,0.5) and (1,1) and stops there. Is there any way of extending both sides of the parabola?

0

2 Answers 2

1

I don't have a very clear idea what you mean by extending both sides of the parabola. But maybe this can help you.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepackage{helvet}
\usepackage{sansmath}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ 
xlabel=$X$,
ylabel=$Y$,
axis x line=center, xlabel style={anchor=south west},
axis y line=center, ylabel style={anchor=south west},
xmin=-4,
xmax=4,
ymin=-1,
ymax=7,
axis line style={thick, shorten > = -0.5cm, shorten < = -0.5cm},
samples=50,
unit vector ratio*=1 1,
font=\sansmath\sffamily,
]

\addplot [domain=-3:3, thick, black, smooth,<->,>=latex]{abs(x)};
\addplot [domain=-1.75:0, thick, black, smooth,<-,>=latex]{2*x^2};
\addplot [domain=0:2.5, thick, black, smooth,->,>=latex]{x^2};    
\end{axis};

\path (current axis.south west) +(-0.5cm,-0.5cm) (current axis.north east) +(0.5cm,0.5cm);
\end{tikzpicture}
\end{document}

The MWE results in

enter image description here

1

You can try to use shorten < and/or shorten > styles with negative values, but this will "extend" the parabola in a "strange way".

You can use plot to draw a parabola over domain that is larger than [0,1].

\begin{tikzpicture}
  \draw (0,0) -- (2,2);
  \draw (0,0) -- (-2,2);
  \draw[red,thick,shift={(-0.5,0.5)},domain=-2:2] plot (1.5*\x,\x*\x/2);
  \draw (-0.5,0.5) parabola (1,1);
\end{tikzpicture}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .