Question

Newton's method in Python The polynomial function Implement the polynomial function. The function computes where ....

Newton's method in Python

The polynomial function

Implement the polynomial function. The function computes $f(x)$ where $f(x) = ax^3 + bx^2 + cx + d$ .

def poly(x, a, b, c, d):
    #
    # complete
    #
    pass

The derivative of the polynomial

Implement the derivative function given by $f'(x) = 3ax^2 + 2bx + c$ .

def poly_der(x, a, b, c, d):
    #
    # complete
    #
    pass

Newton's method

Implement Newton's method by updating the solution guess iteratively. The function returns a tuple of $(x, f(x))$ .

def newtons_method(a, b, c, d, n, x0):
    #
    # complete
    #
    pass
poly(10, 1, 2, 3, 4)
poly_der(10, 1, 2, 3, 4)
newtons_method(1, 2, 3, 4, n=10, x0=0.0)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#while pasting the tabs/indentations may get disturbed, please refer pic for correct tabs
def poly(x, a, b, c, d):
return a*x**3 +b*x**2+c*x+d;

def poly_der(x,a,b,c,d):
return 3*a*x**2 +2*b*x+c;

def newtons_method(a,b,c,d,n,x0):
count=0;
x=x0;
while(count<=n):
x=x0-(poly(x0, a, b, c, d)/poly_der(x0,a,b,c,d))
x0=x
count=count+1;
return (x,poly(x, a, b, c, d))

print(newtons_method(1,2,3,4,10,0))

Add a comment
Know the answer?
Add Answer to:
Newton's method in Python The polynomial function Implement the polynomial function. The function computes where ....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following function with a real variable, x: ?(?) = ?3 - 3?2 + 6?...

    Consider the following function with a real variable, x: ?(?) = ?3 - 3?2 + 6? + 10 a. Write a Python function for the derivative of f(x) that takes x and returns the derivative of f(x). Take the derivative of f(x) analytically with respect to x before writing the function. b. Write a Python code that approximately finds the real root, x0, of f(x) such that f(x0)~0 using the Newton-Raphson method. The code is expected to get an initial...

  • Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any a...

    Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any arbitrary function f given an initial guess xo, an absolute error tolerance e and a maximum number of iterations max iter. Follow mynewton.m template posted in homework 2 folder on TritonED for guidance. You are not required to use the template. The function should return the approximated root ^n and the number of steps n taken to reach the solution. Use function mynewton.m to perform...

  • . (25 points) The recurrence relation for the Newton's Raphson method is a)0.1.2 f(r.) F(z.) The ...

    . (25 points) The recurrence relation for the Newton's Raphson method is a)0.1.2 f(r.) F(z.) The derivative of the function can be approximately evaluated using finite-difference method. Consider the Forward and Centered finite-difference formulas Forward Finite-Difference Centered Finite-Difference 2h It is worthwhile to mention that modified secant method was derived based on the forward finite- difference formula. Develop a MATLAB functions that has the following syntax function [root,fx,ea,iter]-modnetraph (func,x0,h,es,maxit,sethod, varargin) % modnevtraph: root location zeroes of nonlinear equation f (x)...

  • Implement a function double polynom(double x, const vector<double> & a); that computes the value of the...

    Implement a function double polynom(double x, const vector<double> & a); that computes the value of the polynomial functionfn(x)=a0 +a1x+···+anxn. Here the input vector<double> a contains the coefficients of the polynomial function and the value of n is determined by the size of a. can you solve this for c++? thanks.

  • Problem 1 (Matlab): One of the most fundamental root finding algorithms is Newton's Method. Given a real-valued, di...

    Problem 1 (Matlab): One of the most fundamental root finding algorithms is Newton's Method. Given a real-valued, differentiable function f, Newton's method is given by 1. Initialization: Pick a point xo which is near the root of f Iteratively define points rn+1 for n = 0,1,2,..., by 2. Iteration: f(xn) nt1 In 3. Termination: Stop when some stopping criterion occurs said in the literature). For the purposes of this problem, the stopping criterion will be 100 iterations (This sounds vague,...

  • Implement a Python function that prints integers from a to b. The main part of the...

    Implement a Python function that prints integers from a to b. The main part of the program should ask the user to input a and b and call the function. # Display integers a, a+1, a+2, ..., b def display(a,b): ## complete your work here ## return a = int(input("Please prvide a value for a: ")) b = int(input("Please prvide a value for b: ")) display(a,b)

  • Newton's Method in MATLAB During this module, we are going to use Newton's method to compute...

    Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...

  • pls answer e. 5. Newton's Method a. Discuss the use of Newton's method to approximate solutions...

    pls answer e. 5. Newton's Method a. Discuss the use of Newton's method to approximate solutions to a system of n nonlinear equations with n unknowns. b. Write the linear system of equations given by -200u+ 100u, = sin(0.1) 1001 - 200u2 + 100u3 = sin(0.2) 1002 - 200uz + 100u4 = sin(0.3) 100u3 - 2004 + 100us = sin(0.4) 100u4 - 200us + 100u = sin(0.5) 100us - 2004g + 100u, = sin(0.6) 1006 - 2004; + 100ug =...

  • I'm working on the newton's method on matlab, could someone help me and show what two...

    I'm working on the newton's method on matlab, could someone help me and show what two lines are needed to be added in the codes in order to make this function work? function sample_newton(f, xc, tol, max_iter) % sample_newton(f, xc, tol, max_iter) % finds a root of the given function f over the interval [a, b] using Newton-Raphson method % IN: % f - the target function to find a root of % function handle with two outputs, f(x), f'(x)...

  • Using Python 3 Implement the calculator for the date of Easter. The following algorithm computes the...

    Using Python 3 Implement the calculator for the date of Easter. The following algorithm computes the date for Easter Sunday for any year between 1900 to 2099. Ask the user to enter a year. Compute the following: a = year % 19 b = year % 4 c = year % 7 d = (19 * a + 24) % 30 e = (2 * b + 4 * c + 6 * d + 5) % 7 dateOfEaster =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT