Question: SOLVE IN PYTHON A) Write down a NON-vectorized function that estimates this sum. -> Note that the function 'f' has to be passed as an
SOLVE IN PYTHON
A) Write down a NON-vectorized function that estimates this sum.
-> Note that the function 'f' has to be passed as an argument to your function
->Import random to generate your random numbers
B) Write down a vectorized function that estimated this sum.
C) Let f(x) = sinx , a = 0 , b = pi/2
choose n = 10, estimate answers from both methods; choose n = 10^6, estimate answers from both methods.



The probability theory approach People who are into probability theory usually like to interpret integrals as mathematical expectations of a random variable. More precisely, the inte gral (x)dx can be expressed as a mathematical expectation of f(x) if x is a uni- Ja f formly distributed random variable on [a,b]. This expectation can be estimated by the average of random samples, which results in the Monte Carlo integration method. To see this, we start with the formula for the probability density functiorn for a uniformly distributed random variable X on [a,b]: (b-a)-1, xe[a,b] 0 otherwise Now we can write the standard formula for the mathematical expectation E(f(X)): o0 E(f(X))= | f(x)p(x)dx= | f(x)--dx= (b-a) | f(x)dx Cl The last integral is exactly what we want to compute. An expectation is usually estimated from a lot of samples, in this case uniformly distributed random numbers xo, ..., xn-1 in [a, b], and computing the sample mean: The probability theory approach People who are into probability theory usually like to interpret integrals as mathematical expectations of a random variable. More precisely, the inte gral (x)dx can be expressed as a mathematical expectation of f(x) if x is a uni- Ja f formly distributed random variable on [a,b]. This expectation can be estimated by the average of random samples, which results in the Monte Carlo integration method. To see this, we start with the formula for the probability density functiorn for a uniformly distributed random variable X on [a,b]: (b-a)-1, xe[a,b] 0 otherwise Now we can write the standard formula for the mathematical expectation E(f(X)): o0 E(f(X))= | f(x)p(x)dx= | f(x)--dx= (b-a) | f(x)dx Cl The last integral is exactly what we want to compute. An expectation is usually estimated from a lot of samples, in this case uniformly distributed random numbers xo, ..., xn-1 in [a, b], and computing the sample mean
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
