Question: 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

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.

Problem 1

Write a function with the header: function [xNew, count] = myFalsePos (f, xLeft, xRight, tol) which takes as input f: a function handle xLeft: the initial left bracket around a root xRight: the initial right bracket around a root tol: a tolerance above which the algorithm will keep iterating. And uses the False Position method to return the root (xNew). 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 Case: >> [s, count] = myFalsePos(f, 0, 2, .00000000001) s = 0.958192178746198 count = 6

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!