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 ElementWise 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 on the interval can be calculated as
This can be rearranged to solve for the integral
This means that if we know the average value of a function on a finite interval to then we can calculate the value of the definite integral on that the interval. Since the mean value of a function is simply
The integral becomes
Project Write a MatLab code that will estimate the integral of a function on the interval using Monte Carlo integration.
Your program will prompt the user to enter a function using getfunction. It will also have the user enter the endpoints for the integration, a and It must error check that It will also prompt for an integer value that is at least 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 random numbers between a and It will then evaluate the function at each point creating a new vector. It calculate the sum of the function vector, and divide by 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 printresults 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
