Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in Python with the following instructions: you are to write a program that will find a root of a cubic polynomial. A

Write a program in Python with the following instructions:

you are to write a program that will find a root of a cubic polynomial. A cubic polynomial is of the form:

fx= Ax3+Bx2+Cx+D

A root of the polynomial is a value, x, such that f(x)=0. For a generic cubic polynomial, there will be one local maximum, and one local minimum, and the curve will go off to negative infinity in one direction, and positive infinity in another.

You should write a program that takes in the coefficients of the polynomial: A, B, C, and D, along with a bound on one single root: a,b. The user should be expected to input a and b such that a<b and there is exactly one single root of the polynomial between a and b. You should report the value of the root, accurate to within 10-6.

To do this, note that you can use the following procedure, known as bisection. It is a form of what is more generally known as binary search:

  • Because the root is a single root, either f(a) or f(b) will be positive, and the other will be negative.
  • You can generate the midpoint of the interval from a to b, by finding the value halfway between a and b. Call this point p.
  • If you evaluate f(p), it will be either positive or negative (or possibly, be the root itself, if f(p)=0).
  • This will enable you to narrow the interval to either [a,p] or to [p,b].
  • You can continue doing this until your interval is less than 10-6 wide.

your program should do the following:

  • Read in the coefficients of the polynomial from the user
  • Read in the upper and lower bounds around a single root of the polynomial
  • Determine the value of that root to within 10-6
  • Print the result of that root finding, as a single number
  • Print out how many iterations it took to find that root.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

=+ (b) Show that P[n- 1 max 0. Relate to Theorem 14.3.

Answered: 1 week ago