Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions