1

I have a tikz picture and wanted to include a curve whith the following form:

1/(x^2+1)

I can plot the function for a positive domain, e.g. [1,4]:

\draw[domain=1:4,smooth,variable=\x] plot ({\x},{1/(\x^2+1)});

I would like to be able to plot the function from [-4,4].

3
  • Okey i solved it myself, the solution is to replace '\x^2' with '\x*\x'
    – Josh
    Dec 9, 2014 at 8:44
  • Thanks for sharing the solution. Can you post your answer using the answer field below? That makes it easier for other users to fiend the solution.
    – Johannes_B
    Dec 9, 2014 at 9:20
  • @Johannes_B good idea, done!
    – Josh
    Dec 9, 2014 at 9:44

1 Answer 1

4

The solution is to replace \x^2 by \x*\x

It would look like this:

\begin{tikzpicture}
\fill[pattern=north west lines,opacity=.3] (-4,-1.11803*3) -- plot [domain=-4:4] ({\x},{-3/(\x*\x+2)-1.11803*3}) -- (4,-1.11803*3) -- cycle;

\draw[<-]    (1.5,{-3/(1.5*1.5+2)-1.11803*3}) -- (2,-4.5)   node[right] {$U(x)$}; 
\draw[<-]    (-1.5,-3.6) -- (-2,-4.5)   node[left] {$\displaystyle\int_{-\infty}^{\infty}\!\!\!\!\mbox{d}x \:U(x)$}; 
\draw[red,thick,domain=-4:4,smooth,samples=200,variable=\x] plot ({\x},{-3/(\x*\x+2)-1.11803*3});
\draw[red,dotted,thick,domain=-4:-5,smooth,samples=200,variable=\x] plot ({\x},{-3/(\x*\x+2)-1.11803*3});
\draw[red,dotted,thick,domain=4:5,smooth,samples=200,variable=\x] plot ({\x},{-3/(\x*\x+2)-1.11803*3});

\draw (0,0) circle (1.5cm);
\draw[->]    (0,0) -- (0,-1.5) node[midway,left] {$R$}; 
\draw[->]    (0,0) -- (1,-1.11803) node[midway,right] {$R$}; 
\draw[<->]    (1,-1.11803) -- (1*3,-1.11803*3) node[midway,right] {$R$}; 
\draw[<->]    (0,-1.5) -- (0,-1.11803*3) node[midway,right] {$z$}; 
\draw[-latex]    (-5,-1.11803*3) -- (5,-1.11803*3); 
\draw[|->|]    (0,-1.11803*3-0.2) -- (3,-1.11803*3 -0.2) node[midway,below] {$x$};
\end{tikzpicture}

resulting as: enter image description here

You must log in to answer this question.

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