The function e -x^2 does not have an antiderivative that can be expressed in ter
ID: 3556505 • Letter: T
Question
The function e-x^2 does not have an antiderivative that can be expressed in terms of elementary functions (ex, sin x, etc), so the integral of this function must be estimated by some numerical technique.
Approximate the integral:
by using the Monte Carlo method. (remember that integral is the areaunderneath the line )
Hint: You need to include <math.h> to calculate theby using exp(-(x*x)).
Sample Input/Output:
(Input is in bold)
Run again(1=yes,0=no)? 1
How many trials? 100
Integral = 0.720000
Run again(1=yes,0=no)? 1
How many trials? 10000
Integral = 0.746400
Run again(1=yes,0=no)? 1
How many trials? 1000000
Integral = 0.746515
Explanation / Answer
#include #include #include #include #define SEED 35791246 main(int argc, char* argv) { int niter=0; double x,y; int i,count=0; /* # of points in the 1st quadrant of unit circle */ double z; double pi; printf("Enter the number of iterations used to estimate pi: "); scanf("%d",&niter); /* initialize random numbers */ srand(SEED); count=0; for ( i=0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.