Question: function [x] = myNewtontol(f, fderv, x0, tol) $myNewton: newtons method for roots Calculates a root of a function based on the initial guess until the

 function [x] = myNewtontol(f, fderv, x0, tol) $myNewton: newtons method forroots Calculates a root of a function based on the initial guess

function [x] = myNewtontol(f, fderv, x0, tol) $myNewton: newtons method for roots Calculates a root of a function based on the initial guess until the & desired tolerence is met. finputs: $ f: the function to be rooted $ fderv: the derivative of the target function 8 x0: the initial guess (hopefully somewhere close to a root) 8 tol: the tolerance for residue at the estimate $outputs: x: the final estimate of the root that was calculated x=x0; n=0; while abs (f(x) ) >tol n=n+1; x=x-f(x)/fderv (x); $ newton's formula $failsafe for the probability of an infinite loop (convergence with newton's method is not guaranteed) if n>1000 warning ("upper limit for iteration has been met, estimate is probably bad!") break; end end end 50 points) Create a Matlab function that, Takes as input: a function "f", its derivative fderv", the endpoints of an interval a and b. Checks if a b changes the value of a with the value of b and vice-versa. If a = b the function should error out using the "error("an explanation for failure) command of matlab. Generates an array x slicing the interval [a, b] with a sampling length of 0.001. Evaluates the function on the above array and gets a new array y. The evaluation array y is searched for any value between (-0.0001, 0.0001) and the relevant x points are recorded into a new array named "xguess. You can do this by using a for loop, and getting the length of the array y with "length(y). Hint: create a new empty array with "xguess=[]" before the loop and place every new item you find to the tail of the array with the syntax "xguess=[xgues, whatever new item] The attached myNewton Tol function is called for the inputs of this function and a tolerance of 0.0001, and the result recorded as xNewton. The number xNewtol is compared with every entry of xguess (again perhaps with a loop). If any entry of xguess is at a distance of 0.000001 or less function outputs 1, if not function outputs 0. Comment everything like we did in the lecture, and try to explain what you think this function is for. function [x] = myNewtontol(f, fderv, x0, tol) $myNewton: newtons method for roots Calculates a root of a function based on the initial guess until the & desired tolerence is met. finputs: $ f: the function to be rooted $ fderv: the derivative of the target function 8 x0: the initial guess (hopefully somewhere close to a root) 8 tol: the tolerance for residue at the estimate $outputs: x: the final estimate of the root that was calculated x=x0; n=0; while abs (f(x) ) >tol n=n+1; x=x-f(x)/fderv (x); $ newton's formula $failsafe for the probability of an infinite loop (convergence with newton's method is not guaranteed) if n>1000 warning ("upper limit for iteration has been met, estimate is probably bad!") break; end end end 50 points) Create a Matlab function that, Takes as input: a function "f", its derivative fderv", the endpoints of an interval a and b. Checks if a b changes the value of a with the value of b and vice-versa. If a = b the function should error out using the "error("an explanation for failure) command of matlab. Generates an array x slicing the interval [a, b] with a sampling length of 0.001. Evaluates the function on the above array and gets a new array y. The evaluation array y is searched for any value between (-0.0001, 0.0001) and the relevant x points are recorded into a new array named "xguess. You can do this by using a for loop, and getting the length of the array y with "length(y). Hint: create a new empty array with "xguess=[]" before the loop and place every new item you find to the tail of the array with the syntax "xguess=[xgues, whatever new item] The attached myNewton Tol function is called for the inputs of this function and a tolerance of 0.0001, and the result recorded as xNewton. The number xNewtol is compared with every entry of xguess (again perhaps with a loop). If any entry of xguess is at a distance of 0.000001 or less function outputs 1, if not function outputs 0. Comment everything like we did in the lecture, and try to explain what you think this function is for

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!