Gaussian Probability: 1 to 2 in tikz

  • Context: MHB 
  • Thread starter Thread starter karush
  • Start date Start date
  • Tags Tags
    Gaussian Probability
Click For Summary

Discussion Overview

The discussion revolves around the use of TikZ for graphing Gaussian probability distributions, specifically focusing on the area under the curve between specific values (P(1

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant shares a TikZ code snippet for graphing the Gaussian function and expresses uncertainty about deriving the area from the function.
  • Another participant notes that TikZ does not have built-in functions for calculating the area under the Gaussian graph or for performing integration.
  • A participant contrasts TikZ with Desmos, suggesting that while TikZ is more exotic, Desmos has integration capabilities.
  • Further, a participant proposes a workaround using TikZ to approximate the area under the Gaussian curve by declaring a normcdf function and using it to evaluate the area.
  • Another participant expresses admiration for the proposed solution, indicating interest in the method shared.

Areas of Agreement / Disagreement

Participants generally agree that TikZ lacks direct integration capabilities, while there is some debate about the comparative advantages of TikZ versus Desmos. The discussion remains unresolved regarding the best approach to calculate the area under the Gaussian curve using TikZ.

Contextual Notes

Limitations include the lack of direct integration functions in TikZ and the need for workarounds to approximate areas under curves. The discussion also highlights the potential for misunderstandings regarding the capabilities of different graphing tools.

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
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • Poll Poll
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 0 ·
Replies
0
Views
6K