Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

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_2

Step: 3

blur-text-image_3

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

Th ey told me Id have to write a lett er. Whos got time for that?

Answered: 1 week ago