Root Finding You are to write a program named Lab5a_Act1.py that will find one single root of a cubic polynomial. A cubic polynomial is of the form: f(x) = Ax² + Bx² + Cx + D We are only concerned with single ronts Method for Finding a Single Root: One valid method for finding a single root uses a bisection procedure. With this method, we are trying to find an interval on x such that the root lies in this interval, but the interval width is yery small. So, we are not trying to find a value of x sych that f(x) is exactly zero. Instead, we are trying to find an interval on x which contains the root and Which is of arbitrarily smll width. Let's assume that we know that a single root lies between x = a and x = b. We can express this interval as [a, b]. Let's also assume that we know that a < b so that a lies to the left of b on the x-axis. There are two cases to consider: 1. Case 1: The plotted curve is increasing from left to right. (See Case 1 in figure above/left.) a. Therefore, f(a) is negative and f(b) is positive, provided that neither x = a nor x = b is a root. b. If the interval [a, b] is wider than a specified tolerance, we bisect the interval. This involves finding x = p such that p is halfway between a and b. c. Our new interval will either be [a, p] or [p, b]. How do we choose? d. First, evaluate f(p). i. If f(p) < 0, replace a such that the new interval is [p, b]. i. If f(p) > 0, replace b such that the new interval is [a, p]. e. Note that after the bisection, the interval is half the width of the previous interval. f. Continue this procedure until we find an interval of width < tolerance and specify either of the interval limits as the root. 2. Case 2: The plotted curve is decreasing from left to right. (See Case 2 in figure above/left.) a. Therefore, f(a) is positive and f(b) is negative, provided that neither x = a nor x = b is a root. b. If the interval [a, b] is wider than a specified tolerance, we bisect the interval. This involves finding x = p such that p is halfway between a and b. c. Our new interval will either be [a, p] or [p, b]. How do we choose? d. First, evaluate f (p). i. If f(p) > 0, replace a such that the new interval is [p, b]. i. If f(p) < 0, replace b such that the new interval is [a, p]. e. Note that after the bisection, the interval is half the width of the previous interval. f. Continue this procedure until we find an interval of width < tolerance and specify either of the interval limits as the root.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

5act1 Please help me answer this problem in python programming. I have included an image with information that might help. The problem is listed under the title writing the Python code

Root Finding
You are to write a program named Lab5a_Act1.py that will find one single root of a cubic polynomial. A
cubic polynomial is of the form:
f(x) = Ax³ + Bx² + Cx + D
We are only concerned with single roots
Method for Finding a Single Root:
One valid method for finding a single root uses a bisection procedure. With this method, we are trying
to find an interval on x such that the root lies in this interval, but the interval width is yery small.
So, we are not trying to find a value of x sych that f(x) is exactly zero. Instead, we are trying to find an
interval on x which contains the root and Which is of arbitrarily small width.
Let's assume that we know that a single root lies between x = a and x = b. We can express this interval
as [a, b]. Let's also assume that we know that a < b so that a lies to the left of b on the x-axis. There are
two cases to consider:
1. Case 1: The plotted curve is increasing from left to right. (See Case 1 in figure above/left.)
a. Therefore, f(a) is negative and f(b) is positive, provided that neither x = a nor x = b
is a root.
b. If the interval [a, b] is wider than a specified tolerance, we bisect the interval. This
involves finding x = p such that p is halfway between a and b.
c. Our new interval will either be [a, p] or [p, b]. How do we choose?
d. First, evaluate f(p).
i. If f(p) < 0, replace a such that the new interval is [p, b].
ii. If f (p) > 0, replace b such that the new interval is [a, p].
e. Note that after the bisection, the interval is half the width of the previous interval.
f. Continue this procedure until we find an interval of width < tolerance and specify either
of the interval limits as the root.
2. Case 2: The plotted curve is decreasing from left to right. (See Case 2 in figure above/left.)
a. Therefore, f(a) is positive and f(b) is negative, provided that neither x = a nor x = b
is a root.
b. If the interval [a, b] is wider than a specified tolerance, we bisect the interval. This
involves finding x =p such that p is halfway between a and b.
c. Our new interval will either be [a, p] or [p, b]. How do we choose?
d. First, evaluate f(p).
i. If f(p) > 0, replace a such that the new interval is [p, b].
ii. If f(p) < 0, replace b such that the new interval is [a, p].
e. Note that after the bisection, the interval is half the width of the previous interval.
f. Continue this procedure until we find an interval of width < tolerance and specify either
of the interval limits as the root.
Transcribed Image Text:Root Finding You are to write a program named Lab5a_Act1.py that will find one single root of a cubic polynomial. A cubic polynomial is of the form: f(x) = Ax³ + Bx² + Cx + D We are only concerned with single roots Method for Finding a Single Root: One valid method for finding a single root uses a bisection procedure. With this method, we are trying to find an interval on x such that the root lies in this interval, but the interval width is yery small. So, we are not trying to find a value of x sych that f(x) is exactly zero. Instead, we are trying to find an interval on x which contains the root and Which is of arbitrarily small width. Let's assume that we know that a single root lies between x = a and x = b. We can express this interval as [a, b]. Let's also assume that we know that a < b so that a lies to the left of b on the x-axis. There are two cases to consider: 1. Case 1: The plotted curve is increasing from left to right. (See Case 1 in figure above/left.) a. Therefore, f(a) is negative and f(b) is positive, provided that neither x = a nor x = b is a root. b. If the interval [a, b] is wider than a specified tolerance, we bisect the interval. This involves finding x = p such that p is halfway between a and b. c. Our new interval will either be [a, p] or [p, b]. How do we choose? d. First, evaluate f(p). i. If f(p) < 0, replace a such that the new interval is [p, b]. ii. If f (p) > 0, replace b such that the new interval is [a, p]. e. Note that after the bisection, the interval is half the width of the previous interval. f. Continue this procedure until we find an interval of width < tolerance and specify either of the interval limits as the root. 2. Case 2: The plotted curve is decreasing from left to right. (See Case 2 in figure above/left.) a. Therefore, f(a) is positive and f(b) is negative, provided that neither x = a nor x = b is a root. b. If the interval [a, b] is wider than a specified tolerance, we bisect the interval. This involves finding x =p such that p is halfway between a and b. c. Our new interval will either be [a, p] or [p, b]. How do we choose? d. First, evaluate f(p). i. If f(p) > 0, replace a such that the new interval is [p, b]. ii. If f(p) < 0, replace b such that the new interval is [a, p]. e. Note that after the bisection, the interval is half the width of the previous interval. f. Continue this procedure until we find an interval of width < tolerance and specify either of the interval limits as the root.
Plot of Cubic Polynomial
120
100
The plot to the left is an example of Case 1. f(a) is
negative, f(b) is positive, and p is halfway between a and
b. We evaluate f (p) and find that f(p) > 0. We replace b
so that the new interval is [a, p].
60
40
20
-20
40
-3
-2
X values
Writing the Python Code:
Write the code including the features listed below. Before developing your code, you should come.UD.
with at least five (5) test cases. Test cases should indicate a curve (the four coefficients for the curve), as
well as a large starting bound on the root (values of a and b, with b >= a + 1), and the expected
answer (the root). Your team needs to find examples of cubic polynomials for which you know the roots.
Google may prove useful for that. Your code should include documentation of these five (or more) test
cases in comments, near the top of the program (after your standard header). Use the Python code,
plotCubicPolynomial.py, posted with this to plot your cubic polynomial and determine appropriate
values for a and b.
Requirements:
You should create a program that performs bisection to determine a single root of a cubic polynomial.
More specifically, your program should do the following:
• Take as input from the user the coefficients of the cubic polynomial via the keyboard
• Take as input from the user the lower (a) and upper (b) bounds of an interval on x that includes
one single root of the cubic polynomial
• Determine the value of that root to within 10 tolerance
• Print the value of the root found (use the average of the interval bounds) to three (3) decimal
places
• Print out how many iterations it took to find that root
• Include appropriate comments in your code so that we can follow your logic
• Also, as stated above, include the detail of your five test cases in comments just under the
header information
Use the output format shown below (user input is bold and red text)
Output using 2x + 3x² – 11x – 6 = 0 and interval [-4, –2]:
Enter the coefficient A: 2
Enter the coefficient B: 3
Enter the coefficient C: -11
Enter the coefficient D: -6
Enter the lower bound of the interval: -4
Enter the upper bound of the interval: -2
The root is at x = -3.000
It took 21 iterations to find the root
sanen A
Transcribed Image Text:Plot of Cubic Polynomial 120 100 The plot to the left is an example of Case 1. f(a) is negative, f(b) is positive, and p is halfway between a and b. We evaluate f (p) and find that f(p) > 0. We replace b so that the new interval is [a, p]. 60 40 20 -20 40 -3 -2 X values Writing the Python Code: Write the code including the features listed below. Before developing your code, you should come.UD. with at least five (5) test cases. Test cases should indicate a curve (the four coefficients for the curve), as well as a large starting bound on the root (values of a and b, with b >= a + 1), and the expected answer (the root). Your team needs to find examples of cubic polynomials for which you know the roots. Google may prove useful for that. Your code should include documentation of these five (or more) test cases in comments, near the top of the program (after your standard header). Use the Python code, plotCubicPolynomial.py, posted with this to plot your cubic polynomial and determine appropriate values for a and b. Requirements: You should create a program that performs bisection to determine a single root of a cubic polynomial. More specifically, your program should do the following: • Take as input from the user the coefficients of the cubic polynomial via the keyboard • Take as input from the user the lower (a) and upper (b) bounds of an interval on x that includes one single root of the cubic polynomial • Determine the value of that root to within 10 tolerance • Print the value of the root found (use the average of the interval bounds) to three (3) decimal places • Print out how many iterations it took to find that root • Include appropriate comments in your code so that we can follow your logic • Also, as stated above, include the detail of your five test cases in comments just under the header information Use the output format shown below (user input is bold and red text) Output using 2x + 3x² – 11x – 6 = 0 and interval [-4, –2]: Enter the coefficient A: 2 Enter the coefficient B: 3 Enter the coefficient C: -11 Enter the coefficient D: -6 Enter the lower bound of the interval: -4 Enter the upper bound of the interval: -2 The root is at x = -3.000 It took 21 iterations to find the root sanen A
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY