Question: Problem 2: (5 Points). Write a function with the header function [s, count] = myMonteCarlo(f, xLeft, xRight, tol) which uses bracketing logic and random numbers

Problem 2: (5 Points). Write a function with the header function [s, count] = myMonteCarlo(f, xLeft, xRight, tol)

which uses bracketing logic and random numbers to solve for the root of f. Start from your code for Problem 1, then modify the update equation to randomly choose a number betweeen xLeft and xRight. That is your xNew. Note your code will take a different number of iterations to find the root every time you run it, even for the exact same initial bracket, xLeft and xRight. Tips: Be sure to include an iteration counter which will stop the while-loop if the number of iterations get greater than 1000. It is not necessary to print out a convergence table within the while loop. (I.e., there should be no fprintf statements in your code) Test Cases: >> f = @(x) 2*(1-cos(x))+4*(1-sqrt(1-(0.5*sin(x)).^2)) - 1.2; >> [x, count] = myMonteCarlo(f, 0, 2, .00000000001) x = 0.958192178745093 count = 33 >> [x, count] = myMonteCarlo(f, 0, 2, .00000000001) x = 0.958192178745928 count = 50 >> [x, count] = myMonteCarlo(f, 0, 2, .00000000001) x = 0.958192178742504 count = 55 >> [x, count] = myMonteCarlo(f, 0, 2, .00000000001) x = 0.958192178741743 count = 50

please answer in matlab language

Problem 2: (5 Points). Write a function with the header function [s,

count] = myMonteCarlo(f, xLeft, xRight, tol) which uses bracketing logic and random

Problem 2: (5 Points). Write a function with the header -m

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 Databases Questions!