Answered step by step
Verified Expert Solution
Question
1 Approved Answer
NEEDS TO BE IN R 2. Newton's Method Create a function, called newton , that implements the Newton's Method (see HW3 Q3). The inputs include
NEEDS TO BE IN R
2. Newton's Method Create a function, called newton , that implements the Newton's Method (see HW3 Q3). The inputs include the function f for which we want to find the root, the first derivative of f (called df ), the starting value xo , and the threshold in the stopping criterion (called stop ; equal to 0.0001 in HW3 Q3). The output is a list that has three objects: the value of x at the last step (called x.final ), the total number of steps (called total.step ), and the value of f at the last step (called f.final ). a. Test your function by running the code result1 = newton(f=fi, df=df1, x0=2, stop=0.0001) where fi is the function fi(x) = 23 3x 3 and dfi is its first derivative f(x) = 3x2 3. Print the output resulti. The root you found here should be the same as the one in HW3 Q3. b. Now update your function by including one more input max.step, which represents the maximal number of steps allowed for the Newton's Method. Now the stopping criterion becomes either In - In-1 max.step . Name your new function as newton.new. Show your function. Test your function by running the code result2 = newton.new(f=f2, df-df2, x0=5, stop=0.0001, max.step=10) where f2 is the function f2 ) = x 2.+ 2 and df2 is its first derivative f (x) = 3.02 2. Print the output result2. Run the code result3 = newton(f=f2, df=df2, x0=5, stop=0.0001) Print the output results and compare it with result2. 2. Newton's Method Create a function, called newton , that implements the Newton's Method (see HW3 Q3). The inputs include the function f for which we want to find the root, the first derivative of f (called df ), the starting value xo , and the threshold in the stopping criterion (called stop ; equal to 0.0001 in HW3 Q3). The output is a list that has three objects: the value of x at the last step (called x.final ), the total number of steps (called total.step ), and the value of f at the last step (called f.final ). a. Test your function by running the code result1 = newton(f=fi, df=df1, x0=2, stop=0.0001) where fi is the function fi(x) = 23 3x 3 and dfi is its first derivative f(x) = 3x2 3. Print the output resulti. The root you found here should be the same as the one in HW3 Q3. b. Now update your function by including one more input max.step, which represents the maximal number of steps allowed for the Newton's Method. Now the stopping criterion becomes either In - In-1 max.step . Name your new function as newton.new. Show your function. Test your function by running the code result2 = newton.new(f=f2, df-df2, x0=5, stop=0.0001, max.step=10) where f2 is the function f2 ) = x 2.+ 2 and df2 is its first derivative f (x) = 3.02 2. Print the output result2. Run the code result3 = newton(f=f2, df=df2, x0=5, stop=0.0001) Print the output results and compare it with result2Step 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