TikZ graph of e^{(x^2-1)^2} -2

  • MHB
  • Thread starter karush
  • Start date
  • Tags
    Graph
In summary: \addplot[ draw = blue, domain=-1.5:1.5, range=-2:2, samples=50 ] {exp((x^2-1)^2)-2}; \end{axis}\end{tikzpicture}

Tikz should render on PF

  • yes

    Votes: 0 0.0%
  • no

    Votes: 0 0.0%

  • Total voters
    0
  • #1
karush
Gold Member
MHB
3,269
5
ok I tried to tikz graph of e^{x^2-1)^2 -2 just borrowed an example online but this isn't what I want
the domain and range should be equal and want the normal xy axis not a box with tics only at the zeros

$$\begin{axis}
\addplot[
draw = blue,
domain=-2:2,
range=-2:2,
samples=50
] {exp(x^2-1)^2};
\end{axis}
\end{tikzpicture}$$

sorry thot it would render here?
 
Physics news on Phys.org
  • #2
The picture should begin a begin tikzpicture marker.
And dollars should not be used around the picture. It is not a math formula after all.

Since we want to use the package pgfplots, we need load it in the preamble with a [M]%preamble[/M] directive.
You can see examples in the Live TikZ Editor, which you can activate from the MHB Widgets visible at the right when posting.

The result is:
[latexs]\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\begin{axis}
\addplot[
draw = blue,
domain=-2:2,
range=-2:2,
samples=50
] {exp(x^2-1)^2};
\end{axis}
\end{tikzpicture}[/latexs]
\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\begin{axis}
\addplot[
draw = blue,
domain=-2:2,
range=-2:2,
samples=50
] {exp(x^2-1)^2};
\end{axis}
\end{tikzpicture}

Use [M]ymax[/M] to set the range of the y-axis as a property of the [M]axis[/M].
Use [M]axis lines=middle[/M] to get normal axis lines.
And while we're at it, let's add [M]grid=both[/M] for some nice grid lines. ;)

[latexs]\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\begin{axis}[ymax=6, axis lines=middle, grid=both]
\addplot[
draw = blue,
domain=-2:2,
range=-2:2,
samples=50
] {exp(x^2-1)^2};
\end{axis}
\end{tikzpicture}[/latexs]
\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\begin{axis}[ymax=6, axis lines=middle, grid=both]
\addplot[
draw = blue,
domain=-2:2,
range=-2:2,
samples=50
] {exp(x^2-1)^2};
\end{axis}
\end{tikzpicture}

If you want, you can also add [M]xmin[/M] and [M]xmax[/M] to control the range of the x-axis.

Oh, and it looks as if you actual want a different formula than [M]exp(x^2-1)^2[/M].
Ah well, we can replace it with [M](exp(x^2-1))^2 - 2[/M] or [M]exp((x^2-1)^2) - 2[/M] depending on which one you wanted. (Thinking)
 
  • #3
Re: tikx graph of e^{x^2-1)^2 -2

?

[DESMOS]advanced: {"version":7,"graph":{"squareAxes":false,"viewport":{"xmin":-2.5,"ymin":-2.5,"xmax":2.5,"ymax":2.5}},"expressions":{"list":[{"type":"expression","id":"graph1","color":"#2d70b3","latex":"y=e^{\\left(x^2-1\\right)^2}-2"},{"type":"expression","id":"2","color":"#388c46"}]}}[/DESMOS]
 
  • #4
actually the desmos graph is the one I would like to duplicate in tikx
guess it is just changing the range limits

xmax and xmin for range ?
 
Last edited:
  • #5
karush said:
actually the desmos graph is the one I would like to duplicate in tikx
guess it is just changing the range limits

xmax and xmin for range ?

If we use the formula [M]exp((x^2-1)^2)-2[/M], then TikZ complains that the values become to large.
We can fix it by reducing the [M]domain[/M] to, say, [M]-1.5:1.5[/M].
Then we don't need [M]ymax[/M] either.

[latexs]\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\begin{axis}[axis lines=middle, grid=both]
\addplot[
draw = blue,
domain=-1.5:1.5,
range=-2:2,
samples=50
] {exp((x^2-1)^2)-2};
\end{axis}
\end{tikzpicture}[/latexs]
\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\begin{axis}[axis lines=middle, grid=both]
\addplot[
draw = blue,
domain=-1.5:1.5,
range=-2:2,
samples=50
] {exp((x^2-1)^2)-2};
\end{axis}
\end{tikzpicture}
 
  • #6
one more question if I may

how do you make the x tics and text only at the zeros
rather than equal distance apart
also the y tics are not needed

kinda new at this so...
 
  • #7
karush said:
one more question if I may

how do you make the x tics and text only at the zeros
rather than equal distance apart
also the y tics are not needed

kinda new at this so...

You mean something like this?
\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\begin{axis}[xmin=-1.8, xmax=1.8, axis lines=middle, ticks=none]
\addplot[
draw = blue,
domain=-1.5:1.5,
range=-2:2,
samples=50
] {exp((x^2-1)^2)-2}
foreach \x [evaluate={\xval=\x}] in {
{-sqrt(1+sqrt(ln(2)))}, {-sqrt(1-sqrt(ln(2)))}, {sqrt(1-sqrt(ln(2)))}, {sqrt(1+sqrt(ln(2)))}
} { (axis cs:{\xval},0) node[below] {\xval} };
\end{axis}
\end{tikzpicture}
 
  • #8
Yep

Was that just off a node?

Assume the numbers were calculated outside of tikx
 
  • #9
karush said:
Yep

Was that just off a node?

Assume the numbers were calculated outside of tikx

It's possible to let TikZ do all of the work as explained here.

I let TikZ do only part of the work though. That is, I found that the zeroes are $\pm\sqrt{1\pm\sqrt{\ln 2}}$ and I left the evaluation to TikZ.
Click on the picture to see the code.
 
  • #10
well that is a very handy thing to know I see lots of uses for that

I tried to add the second derivative graph also on this graph
but it returned operater unknow but I tried exp also and :confused:
$f'' = 4x(x-1)(x+1) \cdot e^{(x^2-1)^2}$the problem is about where it is concave so need f''

so did this but gave it a c-
View attachment 9582

not sure why the tikx code didn't render here so this is an image form overleaf


$f'=e^{(x^2-1)^2}-2 \implies f'' = 4x(x-1)(x+1) \cdot e^{(x^2-1)^2}$
$f''=0$ when $x=0$ and when $x=\pm 1$
 

Attachments

  • Capture.PNG
    Capture.PNG
    4 KB · Views: 100
Last edited:
  • #11
karush said:
well that is a very handy thing to know I see lots of uses for that

I tried to add the second derivative graph also on this graph
but it returned operater unknow but I tried exp also and :confused:
$f'' = 4x(x-1)(x+1) \cdot e^{(x^2-1)^2}$the problem is about where it is concave so need f''

so did this but gave it a c-not sure why the tikx code didn't render here so this is an image form overleaf


$f'=e^{(x^2-1)^2}-2 \implies f'' = 4x(x-1)(x+1) \cdot e^{(x^2-1)^2}$
$f''=0$ when $x=0$ and when $x=\pm 1$

That is actually the first derivative of $f$.
That is, it is $f'$.

Anyway, it works for me:
\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\begin{axis}[xmin=-1.8, xmax=1.8, ymin=-3, ymax=3, axis lines=middle, ticks=none]
\addplot[
draw = blue, smooth, ultra thick,
domain=-1.5:1.5,
] {exp((x^2-1)^2)-2};
\addplot[
draw=red, smooth, ultra thick, dashed,
domain=-1.5:1.5,
smooth
] {4*x*(x-1)*(x+1)*exp((x^2-1)^2)}
foreach \x in {-1,0,1} { (axis cs:{\x},0) node[below right] {\x} };
\end{axis}
\end{tikzpicture}
 
  • #12
total awsome...
 

Related to TikZ graph of e^{(x^2-1)^2} -2

1. What is a TikZ graph?

TikZ is a powerful and flexible tool for creating high-quality graphics in LaTeX. It is commonly used for creating mathematical diagrams, such as graphs, charts, and diagrams.

2. What is the significance of e^{(x^2-1)^2} -2 in this graph?

The function e^{(x^2-1)^2} -2 is known as the "Gaussian curve" or "bell curve," and is commonly used in statistics and probability to represent continuous distributions. In this graph, it is being plotted against the x-axis to show its shape and behavior.

3. How is the graph of e^{(x^2-1)^2} -2 created using TikZ?

The graph is created by first defining a set of x-values and then calculating the corresponding y-values using the given function. These points are then connected using smooth curves to create the graph. TikZ provides a variety of options for customizing the appearance of the graph, such as line color, thickness, and style.

4. How is the graph of e^{(x^2-1)^2} -2 useful in mathematics?

The graph of e^{(x^2-1)^2} -2 can be useful in visualizing the behavior of the Gaussian curve, which has many applications in statistics, physics, and other fields. It can also be used to illustrate concepts such as maximum and minimum values, inflection points, and concavity in calculus.

5. Can the graph of e^{(x^2-1)^2} -2 be modified or edited in TikZ?

Yes, the graph can be modified in TikZ by changing the function, adjusting the range of x and y values, or adding additional elements. Additionally, the graph can be exported as a high-quality image for use in other documents or presentations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
829
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
983
Back
Top