0

I was wondering if there is a way I can add a function to a tikz drawing without it having to be with the pgfplots package in the axis environment. Im looking to add a sine function along the dashed line in this image:

\begin{center}
\begin{tikzpicture}[scale=0.5]
\draw (0,4) -- (2,4);
\draw (8,4) -- (10,4);
\draw[line width=3, color=blue] (2,0) -- (8,0);
\draw (2,0) -- (2,-0.5);
\draw (8,0) -- (8,-0.5);
\draw[line width=3, color=blue] (2,-0.1) -- (2,4);
\draw[line width=3, color=blue] (8,-0.1) -- (8,4);
\draw[dashed] (1.5,2) -- (9,2);
\node [left] at (1.5,2) {$E<U_o$};
\node [below] at (2,-0.5) {$0$};
\node [below] at (8,-0.5) {$a$};
\node [left] at (0,4) {$U_o$};
\end{tikzpicture}
\end{center}

If it is also possible, I would like to add other functions like exponential functions too. Thanks.

1 Answers1

2

I don't think you looked much, neither in the docs nor on the internet (How to plot functions like ‎‎‎‎‎x=f(y)‎‎ using TikZ? tikz) here is an answer, you will regulate the amplitude and the pulsation.

\documentclass{article}
\usepackage{tikz}
%\usetikzlibrary{calc,matrix,positioning}

\begin{document} \begin{center} \begin{tikzpicture}[scale=0.5] \draw (0,4) -- (2,4); \draw (8,4) -- (10,4); \draw[line width=3, color=blue] (2,0) -- (8,0); \draw (2,0) -- (2,-0.5); \draw (8,0) -- (8,-0.5); \draw[line width=3, color=blue] (2,-0.1) -- (2,4); \draw[line width=3, color=blue] (8,-0.1) -- (8,4); \draw[dashed] (1.5,2) -- (9,2); \node [left] at (1.5,2) {$E<U_o$}; \node [below] at (2,-0.5) {$0$}; \node [below] at (8,-0.5) {$a$}; \node [left] at (0,4) {$U_o$}; \draw[domain=-1:10, smooth, variable=\x, blue] plot ({\x}, {2sin(30\x)+1.5}); \end{tikzpicture} \end{center}

\end{document}

enter image description here

rpapa
  • 12,350