
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
5act1 Please help me answer this problem in python
![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.](https://content.bartleby.com/qna-images/question/d8d61bc1-b6c9-4ebb-ae0a-0fe54d44e28f/10e212c5-58eb-4ce7-bf04-ab10b37e0abe/cnvaega_thumbnail.png)
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](https://content.bartleby.com/qna-images/question/d8d61bc1-b6c9-4ebb-ae0a-0fe54d44e28f/10e212c5-58eb-4ce7-bf04-ab10b37e0abe/pb68c8n_thumbnail.png)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Similar questions
- This code is in Ada code in Ada Please Not in C code Please type your solution out in working code don't just give me an example they may just confuse me more Below is Number_Theory.adb with Ada.Numerics.Generic_Elementary_Functions; package body Number_Theory is -- Instantiate the library for floating point math using Floating_Type. package Floating_Functions is new Ada.Numerics.Generic_Elementary_Functions(Floating_Type); use Floating_Functions; function Factorial(N : in Factorial_Argument_Type) return Positive is begin -- TODO: Finish me! -- -- 0! is 1 -- N! is N * (N-1) * (N-2) * ... * 1 return 1; end Factorial; function Is_Prime(N : in Prime_Argument_Type) return Boolean is Upper_Bound : Prime_Argument_Type; Current_Divisor : Prime_Argument_Type; begin -- Handle 2 as a special case. if N = 2 then return True; end if; Upper_Bound := N - 1; Current_Divisor…arrow_forwardMust be in C# and this assignment only Rare Collection. We can make arrays of custom objects just like we’vedone with ints and strings. While it’s possible to make both 1D and 2D arrays of objects(and more), for this assignment we’ll start you out with just one dimensional arrays.Your parents have asked you to develop a program to help them organize the collectionof rare CDs they currently have sitting in their car’s glove box. To do this, you will firstcreate an AudioCD class. It should have the following private attributes. String cdTitle String[4] artists int releaseYear String genre float conditionYour class should also have the following methods: Default Constructor: Initializes the five attributes to the following default values:◦ cdTitle = “”◦ artists = {“”, “”, “”, “”}◦ releaseYear = 1980◦ genre = “”◦ condition = 0.0 Overloaded Constructor: Initializes the five attributes based on values passedinto the formal parameters◦ If condition is less than 0.0 or greater than 5.0,…arrow_forwardNeed urgent help with Python Decorator creation Never used python decorator before Answer the following questions in the Python decorator context. Your answers should be written in a Markdown file. The quality of answers matters!! What is higher-order function and how it is different from functor? What are First-class objects? What is the significance of functions being First-class objects? What are inner functions? What is the major benefit of inner functions and why is it important for decorator Why @ symbol is called syntactic sugar? What's the biggest advantage of using it when decorators are used? How would it help Python's weak OOP encapsulation of Class? (Hint: google "Python @Property decorator")arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

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 Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

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
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY