Question: Objective Element - Wise Operations. Description Mont Carlo techniques involve modeling real phenonema by generating random values. One such technique is the estimation of a

Objective Element-Wise Operations.
Description Mont Carlo techniques involve modeling real phenonema by generating random values. One such technique is the estimation of a finite integral.
Recall from the Calculus that the average value of a function f(x) on the interval a,b can be calculated as
?bar(f)=1b-aabf(x)dx
This can be rearranged to solve for the integral
abf(x)dx=b-abar(f)
This means that if we know the average value of a function on a finite interval a to b then we can calculate the value of the definite integral on that the interval. Since the mean value of a function is simply
?bar(f)=k=1nf(k)n
The integral becomes
abf(x)dx=(b-a)k=1nf(k)n
Project Write a MatLab code that will estimate the integral of a function f(x) on the interval a,b using Monte Carlo integration.
Your program will prompt the user to enter a function using get_function. It will also have the user enter the endpoints for the integration, a and b. It must error check that b>a. It will also prompt for an integer value n that is at least 1.n is the number of random values to be generated.
Your program will then call a function called integrate that is passed the function you entered, the two endpoints of the interval of integration, and the number of random values to generate.
In the integrate function the program will generate a vector of n random numbers between a and b. It will then evaluate the function at each point creating a new vector. It calculate the sum of the function vector, and divide by n to calculate the mean of the function. Finally it will calculate the estimate of the integral using the equation above. The function will return the value of the definite integral and the average of the function.
The function, endpoints, and number of values will be passed to a print_results function which will print the results using appropriate formatting.
There is a template on Canvas. You should download it as text and then use it as the start of your program. Download it and open it directly in MatLab and start writing the program.
Objective Element - Wise Operations. Description

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!