Numerical integration

A Gauss curve is defined by the function:

The normal distribution is a function which is widely used in statistics. It is defined as the integral of gauss curve:

It is known that the integral from - to is equal to 1. Since the function is symmetrical, F (x) can be rewritten as:

The problem is that it is impossible to calculate this integral by mathematical analysis. We have to calculate it the hard way by splitting the curve into small intervals and calculating the area under each piece. See fig. 3.

The area under the curve of the interval from a to b can be approximated as:

The normal distribution function F (x) is calculated by dividing the interval from 0 to x into n sub-intervals and adding the areas for each sub-interval.

Write the gauss function using the formula above. Write the area function so that it calculates the area over a small interval from a to b by calling the gauss function. Write a function that calculates the normal distribution F (x) by dividing the interval from 0 to x into n sub-intervals and calling the area function for each sub-interval. The function should take x and dx as parameters, where dx = x/n is the length of the sub-intervals.

Write the main program so that it calculates values of F (x) with x and n as inputs.

The accuracy can be improved by calculating the area for the sub-intervals using Simpson's formula:

The value of F (1) = 0.841344746. Try how many sub-intervals you need to get this value with an accuracy of at least six decimals for the simple area formula and for the Simpson formula.