Question
by using R write two functions, root.bisect, and root.regula.falsi. The arguments to both functions are: f, the function whose root will be found a and
by using R write two functions, root.bisect, and root.regula.falsi. The arguments to both functions are: f, the function whose root will be found a and b, which are numbers such that a and b bracket a root of f. The function should check if a and b do bracket a root. If they do not, the function should stop with an appropriate message. tol, a number which is used to determine how much accuracy is desired by the caller. This argument should have a default value. You may have additional arguments, but you must explain what they are and their purpose. The function should return the root found, the values of f evaluated at the root, and the number of iterations required to find the root. The functions should have header comments to describe the arguments, and the output of the function, as well the purpose of the function. The rest of the code should be well-commented. The function root.bisect will find the root using the bisection algorithm. The function root.regula.falsi will find the root using the regula.falsi algorithm. Do not use the R function uniroot or any other R function to find the roots. Your functions should not plot anything. (1) Find the root of the function f <- function(x) { return(2*x*cos(2*x) - (x+1)^2) } for the following intervals: first, a = -3, b = -2. Second, a = -2, b = 4 Report the value of tol used, the roots found, the values of f evaluated at the roots found, and the number of iterations. Run both functions. (2) Now call the two functions to find a root of f in the interval a = 0, b = 5. Report what happens. (3) Find the first three positive roots (that is, the three smallest positive roots) of the function g<- function(x) { return( sin(x^(1/3))+ exp(-3*x) ) } Use both functions to solve this problem. Report the bracketing intervals used as well as the information reported for problem (1). The bracketing intervals should have a length of at least 4. You may plot the function g to find appropriate bracketing intervals, or you may simply evaluate it at random points until you find a bracketing interval. Turn in a hardcopy of your functions, and the results of running your functions to solve problems (1)-(3). You do not have to turn in your method of finding the bracketing intervals for problem (3). You may write an additional function, which uses the modified regula falsi algorithm to find the root. If you decide to write this function, turn in hardcopy of the function, and the results of finding the roots of f and g. You are not required to write this function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started