Calculate Area Under Gaussian Curve w/ Python Reimann Sum

In summary, the conversation discusses a program used to calculate the area under a Gaussian distribution curve, with a Reimann sum program that calculates close to 1.5. The program uses various values such as pi, StandDev, MPCAverage, and IntervalSize to calculate the area. The conversation also mentions a possible mistake in the original code, with a suggested correction.
  • #1
dacruick
1,042
1
Hi I have a program that is to calculate the area under the curve of a Gaussian distribution.
The integral from -inf to inf is 1, and my Reimann sum program calculates close to 1.5pi = numpy.arccos(-1)
a = 1 / (StandDev * pow(2*pi,0.5))
b = MPCAverage #MPC is the x-axis of my gaussian curve
c = StandDev

step = 0.01
IntervalSize = 1.27 #Irrelevant
x2 = 0
s = 0
while s < IntervalSize/step:
x1 = x2
x2 += step
y1 = a*numpy.exp(-(x1-b)**2/(c*c*2))
y2 = a*numpy.exp(-(x2-b)**2/(c*c*2))
Area += (step)*(y2+y1/2)
s += 1
print Area

any tips would be greatly appreciated. Sorry for the spacing error, it won't let me put them in.
 
Technology news on Phys.org
  • #2
Nevermind!

Area += (step)*(y2+y1/2) = DumbMove
Area += (step)*((y2+y1)/2) = BetterMove
 

Related to Calculate Area Under Gaussian Curve w/ Python Reimann Sum

1. How do I calculate the area under a Gaussian curve using Python?

To calculate the area under a Gaussian curve using Python, you can use the Reimann Sum method. This involves dividing the curve into small rectangles and calculating the area of each rectangle. Then, you can sum up all the areas to get an estimate of the total area under the curve.

2. What is a Gaussian curve?

A Gaussian curve, also known as a normal distribution, is a bell-shaped curve that represents the probability distribution of a continuous random variable. It is characterized by its mean and standard deviation, and it is commonly used in statistics and data analysis.

3. Why use the Reimann Sum method to calculate the area under a Gaussian curve?

The Reimann Sum method is a simple and accurate way to estimate the area under a curve. It involves dividing the curve into smaller rectangles, which can provide a good approximation of the curve's shape. This method is also easy to implement in coding, making it a popular choice for calculating the area under a Gaussian curve with Python.

4. Are there other methods for calculating the area under a Gaussian curve?

Yes, there are other methods for calculating the area under a Gaussian curve, such as the Trapezoidal Rule and Simpson's Rule. These methods involve using a more complex formula to estimate the area and can provide a more accurate result compared to the Reimann Sum method.

5. Can I use Python libraries to calculate the area under a Gaussian curve?

Yes, there are several Python libraries such as NumPy and SciPy that have built-in functions for calculating the area under a Gaussian curve. These libraries use advanced mathematical and numerical methods to provide a more accurate and efficient calculation of the area under the curve.

Similar threads

  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
565
  • Programming and Computer Science
Replies
16
Views
2K
  • Precalculus Mathematics Homework Help
Replies
7
Views
1K
Replies
10
Views
721
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
373
  • Programming and Computer Science
Replies
6
Views
1K
  • General Math
Replies
3
Views
969
Back
Top