MHB Gaussian Probability: 1 to 2 in tikz

AI Thread Summary
The discussion revolves around using TikZ and Overleaf for graphing Gaussian functions and calculating areas under the curve. A user expresses difficulty in deriving the area between specific z-values (1 and 2) using the Gaussian function in TikZ, noting that TikZ lacks built-in integration capabilities, unlike Desmos. Another participant suggests a workaround by defining a custom function for the cumulative distribution function (normcdf) to approximate the area under the Gaussian curve. The conversation highlights the limitations of TikZ compared to Desmos while also showcasing a method to achieve the desired calculations within TikZ, emphasizing the need for collaborative coding in Overleaf.
karush
Gold Member
MHB
Messages
3,240
Reaction score
5
\begin{tikzpicture}[scale=0.6]
%preamble \usepackage{pgfplots}
\newcommand\gauss[2]{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))} % Gauss function, parameters mu and sigma
\begin{axis}[every axis plot post/.append style={
mark=none,samples=50,smooth}, % All plots: 50 samples, smooth, no marks
axis x line*=bottom, % no box around the plot, only x axis
axis y line=none, % the * suppresses the arrow tips
enlargelimits=upper, % extend the axes a bit to the right and top
domain=-4:4, % Default for all plots: from -4:4
xtick={1,2},
xticklabels={$1$,$2$},
width=10cm,
height=4cm]
\addplot [fill=cyan!30, draw=none, domain=1:2] {\gauss{0}{1}} \closedcycle;
\addplot {\gauss{0}{1}};
\end{axis}
\end{tikzpicture}

ok this was for P(1<z<2) scaled the graph to .6
the ultimate answer of course is the area in the domain which I don't know if we can derive from the gauss{}{} function
I tried to put the newcommand quass{}{} in the preamble of Overleaf but it didn't take
also thot since all 12 of homework problem are just graphing P()
be nice just have a newcommand \Pg with arguments but also need code that can be colabortive with Overleaf and MHB

again mega mahalo for all the help
 
Physics news on Phys.org
this is what it looks like in Overleaf...

Screenshot 2021-08-13 11.20.21 AM.png
 
I'm afraid that TikZ is not an advanced calculator.
It does not have a function that calculates the area below the Gaussian graph.
And it cannot calculate the integral of a function either.
 
ok well that seems to an advantage of desmos over tikz except tikz is much more exotic
 
Last edited:
karush said:
ok well that seem to an advantage of desmos over tikz except tikz is much more exotic
It appears I misunderstood your question somehow.
Desmos does not have such ability either.
Can you clarify what you want?
 
well i have graph i wanted
i was just curious about integration function in tikx

but yes desmos has a integration function its under misc in the function menu
i have used it many times
 
Well, with a bit of trickery, we can do:
\begin{tikzpicture}[scale=1,
declare function={
gauss(\x,\mean,\sigma) = 1/(\sigma*sqrt(2*pi))*exp(-(\x-\mean)^2/(2*\sigma^2));
normcdf(\x,\m,\s)=1/(1 + exp(-0.07056*((\x-\m)/\s)^3 - 1.5976*(\x-\m)/\s));
},
]
%preamble \usepackage{pgfplots}
\begin{axis}[every axis plot post/.append style={
mark=none,samples=50,smooth}, % All plots: 50 samples, smooth, no marks
axis x line*=bottom, % no box around the plot, only x axis
axis y line=none, % the * suppresses the arrow tips
enlargelimits=upper, % extend the axes a bit to the right and top
domain=-4:4, % Default for all plots: from -4:4
xtick={1,2},
width=10cm,
height=4cm]
\addplot [fill=cyan!30, draw=none, domain=1:2] {gauss(x,0,1)} \closedcycle;
\addplot {gauss(x,0,1)};
\path foreach \y [evaluate=\y as \yeval using {normcdf(\y,0,1)-normcdf(1,0,1)}] in {2} { node[ left ] at (axis cs:{\y},0.05) {\yeval} };
\end{axis}
\end{tikzpicture}

It uses
Code:
[declare function={
    normcdf(\x,\m,\s)=1/(1 + exp(-0.07056*((\x-\m)/\s)^3 - 1.5976*(\x-\m)/\s));
}]
to approximate the area under the Gaussian graph.

And it uses evaluate=\y as \yeval using syntax to convert the function call into a value before printing it.
 
wow that is pretty cool...
 

Similar threads

Replies
2
Views
2K
Replies
2
Views
1K
Replies
4
Views
2K
Replies
8
Views
2K
Replies
1
Views
2K
  • Poll Poll
Replies
11
Views
3K
Replies
5
Views
2K
Replies
0
Views
5K
Back
Top