In python comment the following code line by line as to what each line does
def f(x):
return 6*x**5-5*x**4-4*x**3+3*x**2 #here we define a polynomial
def df(x):
return 30*x**4-20*x**3-12*x**2+6*x #here we define a polynomial
that takes the derivative of the above function f(x)
def dx(f, x):
return abs(0 - f(x))
def newtons_method(f, df, x0, e):
delta = dx(f, x0)
while delta > e:
x0 = x0 - f(x0)/df(x0)
delta = dx(f, x0)
print('Root is at:', x0)
print('f(x) at root is: ', f(x0))
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
def f(x): #define a function f
return 6*x**5-5*x**4-4*x**3+3*x**2 #here we define a polynomial
def df(x):# define the derivative function df
return 30*x**4-20*x**3-12*x**2+6*x #here we define a polynomial
that takes the derivative of the above function f(x)
def dx(f, x):#define a dx function which returns the absolute
value of f(x)
return abs(0 - f(x))
def newtons_method(f, df, x0, e):# Define a function to return the
root from newton method
delta = dx(f, x0)# find the absolute value of function at x0
while delta > e:#while loop to terminate if absolute value of
f(x0) gets less than or equal to e
x0 = x0 - f(x0)/df(x0)# formula of newtons method
x0=x0-f(x0)/df(x0)
delta = dx(f, x0)#evaluate the absolute value of f(x0) again
print('Root is at:', x0)# print the root after it has reached the
tolerance
print('f(x) at root is: ', f(x0))#Print the value of f(x) at value
x0
Kindly revert for any queries
Thanks.
Get Answers For Free
Most questions answered within 1 hours.