[Tex/LaTex] Plotting a function in Latex

plot

How do you draw functions that look like this? I apologize for not providing you with an attempt to solve this problem – I am a second-day user of Latex. Greatly appreciate your help.

\documentclass[paper=a4, fontsize=11pt]{scrartcl} 
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage{fourier} % Use the Adobe Utopia font for the document - comment this line to return to the LaTeX default
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amsthm} % Math packages
\usepackage{sectsty} % Allows customizing section commands
\allsectionsfont{\centering \normalfont\scshape} % Make all sections centered, the default font and small caps

\usepackage{fancyhdr} % Custom headers and footers
\usepackage{xfrac}


\begin{document}
\[ F_x(x) = \left\{ 
  \begin{array}{l l}
    0 & \quad \text{for $x <0$}\\
    x^2 & \quad \text{$0\leq x<0.5$}\\
    1-3(1-x)^2 & \quad \text{$0.5\leq x<1$}\\
    1 & \quad \text{$x\geq 1$}
  \end{array} \right.\]
  \\

\end{document}

Best Answer

\documentclass{article} 

\usepackage{amsmath}
\usepackage{pgfplots}

\begin{document}
\[ F_x(x) = 
  \begin{cases}
    0 & \quad \text{for $x <0$}\\
    x^2 & \quad \text{$0\leq x<0.5$}\\
    1-3(1-x)^2 & \quad \text{$0.5\leq x<1$}\\
    1 & \quad \text{$x\geq 1$}
  \end{cases}
  \]

\begin{tikzpicture}
\begin{axis}
\addplot[smooth,samples=200,domain=-2:0]{0};
\addplot[smooth,samples=200,domain=0:0.5]{x^2};
\addplot[smooth,samples=200,domain=0.5:1]{1-3*(1-x)^2};
\addplot[smooth,samples=200,domain=1:2]{1};
\end{axis}
\end{tikzpicture}
\end{document}

Edited:

Implementing the change suggested by the OP works fine for me:

\documentclass{article} 

\usepackage{amsmath}
\usepackage{pgfplots}

\begin{document}
\[ F_x(x) = 
  \begin{cases}
    0 & \quad \text{for $x <0$}\\
    2x & \quad \text{$0\leq x<0.5$}\\
    6-6x & \quad \text{$0.5\leq x<1$}\\
    1 & \quad \text{$x\geq 1$}
  \end{cases}
  \]

\begin{tikzpicture}
\begin{axis}
\addplot[smooth,samples=200,domain=-2:0]{0};
\addplot[smooth,samples=200,domain=0:0.5]{2*x};
\addplot[smooth,samples=200,domain=0.5:1]{6-6*x};
\addplot[smooth,samples=200,domain=1:2]{1};
\end{axis}
\end{tikzpicture}
\end{document}

Edited again to create red lines and dots, as per request:

\documentclass{article} 

\usepackage[svgnames]{xcolor}
\usepackage{amsmath}
\usepackage{pgfplots}

\begin{document}
\[ F_x(x) = 
  \begin{cases}
    0 & \quad \text{for $x <0$}\\
    x^2 & \quad \text{$0\leq x<0.5$}\\
    1-3(1-x)^2 & \quad \text{$0.5\leq x<1$}\\
    1 & \quad \text{$x\geq 1$}
  \end{cases}
  \]

\begin{tikzpicture}
\begin{axis}
\addplot[Red,smooth,samples=200,domain=-2:0]{0};
\addplot[Red,smooth,samples=200,domain=0:0.5]{x^2};
\addplot[Red,smooth,samples=200,domain=0.5:1]{1-3*(1-x)^2};
\addplot[Red,smooth,samples=200,domain=1:2]{1};
\fill[Red] (axis cs:0,0) circle(0.5mm) (axis cs:0.5,0.25) circle(0.5mm) (axis cs:1,1) circle(0.5mm);
\end{axis}
\end{tikzpicture}
\end{document}