Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a function which uses Newton\'s Method to find the root of a function. Use

ID: 2262826 • Letter: W

Question

write a function which uses Newton's Method to find
the root of a function. Use this new function to find the root of the function
f(x) = x3 + 3x + 1

with an initial guess x0 = -2 and an accuracy a= 10-5.

The function header for the Newton's method should read:
function [ r, iters] = newtonF(f, xL, xR)

a function file, script file, and output file. where the inputs are:
f = the function f(x) for which you want to find the root,
xL = left limit of the interval,
xR = right limit of the interval
and the outputs are:
r = the root
iters = number of iterations performed.

Explanation / Answer

sol)

On the script page:

clear all

f=@(x)x.^3+3*x+1

df=@(x)3*x.^2+3

x0=input('enter initial guess')

while abs(f(x0))>0.00001

x1=x0-(f(x0)/df(x0))

x0=x1

end

On the command window:

    ----------------------------------------------------
Your MATLAB license will expire in 53 days.
Please contact your system administrator or
MathWorks to renew this license.
    ----------------------------------------------------
>> mananya

f =

    @(x)x.^3+3*x+1


df =

    @(x)3*x.^2+3

enter initial guess-2

x0 =

    -2


x1 =

   -1.1333


x0 =

   -1.1333


x1 =

   -0.5707


x0 =

   -0.5707


x1 =

   -0.3449


x0 =

   -0.3449


x1 =

   -0.3223


x0 =

   -0.3223


x1 =

   -0.3222


x0 =

   -0.3222