Question

Develop a python program to find the different solutions, i.e. zero crossings, of a polynomial function...

Develop a python program to find the different solutions, i.e. zero crossings, of a polynomial function using Newton-Raphson’s method over a given range. To do this we will develop three functions: the first should be a function to evaluate the polynomial at a given value of the independent variable; the second function would evaluate the derivative of the polynomial at a given value of the independent variable; finally, the third function would implement Newton-Raphson’s (NR) method to determine a zero of the polynomial in the neighborhood of a specified point where we believe that a solution exists. You would repetitively use this NR function to find solutions starting from the proposed neighborhood values. Test your program on the following polynomials: ?*3 − 9?*2 + 24? − 20 = 0 for ? being in the neighborhood of 0, 2.5, and 6, and ?*3 − 2?*2 − 5? + 6 = 0 for ? being in the neighborhood of -1.5, 0.5, and 2.5. You may want to initially develop the program to be tailored for a third order polynomial. This will make the evaluation and derivative functions almost trivial, i.e. one liners, which is fine. Once the program runs for the two given test data, you may contemplate the challenge of making it more general, capable of working with a polynomial of any order. An additional challenge would be to use your evaluation function to generate multiple values and to select from these the ones that seem closest to a solution and put them in a list of neighborhood values. Note every time the function changes sign between two values, this is an indication that there is a zero of the function between these values.

Homework Answers

Answer #1

Python code for ?*3 − 9?*2 + 24? − 20 = 0 in the neighborhood of 0, 2.5, and 6.

def func( x ):
    return x * x * x - 2 *x * x - 5*x + 6

# Derivative of the above function
# which is 3*x^x - 2*x
def derivFunc( x ):
    return 3 * x * x - 4 * x -5

# Function to find the root
def newtonRaphson( x ):
    h = func(x) / derivFunc(x)
    while abs(h) >= 0.0001:
        h = func(x)/derivFunc(x)
        
        # x(i+1) = x(i) - f(x) / f'(x)
        x = x - h
    
    print("The value of the root is : ",
                             "%.4f"% x)

# Driver program to test above
# Initial values assumed
x0 = 0
x1 = 2.5
x2 = 6
newtonRaphson(x0)
newtonRaphson(x1)
newtonRaphson(x2)

Please refer to the screenshot of the code to understand the indentation of the code


Output:

Hope this helped. Please do upvote and if there are any queries please ask in comments section.

Know the answer?
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
Similar Questions
Python programming Write a program that prompts the user to input the three coefficients a, b,...
Python programming Write a program that prompts the user to input the three coefficients a, b, and c of a quadratic equationax2+bx+c= 0.The program should display the solutions of this equation, in the following manner: 1. If the equation has one solution, display ONE SOLUTION:, followed by the solution, displayed with4 digits printed out after the decimal place. 2. If the equation has two real solutions, display TWO REAL SOLUTIONS:, followed by the two solutions, each displayed with4 digits printed...
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation....
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation. case:    W17400 APIGEE: PEOPLE MANAGEMENT PRACTICES AND THE CHALLENGE OF GROWTH Ranjeet Nambudiri, S. Ramnarayan, and Catherine Xavier wrote this case solely to provide material for class discussion. The authors do not intend to illustrate either effective or ineffective handling of a managerial situation. The authors may have disguised certain names and other identifying information to protect confidentiality. This publication may not be...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT