Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 6 : Finding a Root of a Polynomial Function Consider the function f ( x ) = x ^ 3 4 x ^ 2
Problem : Finding a Root of a Polynomial Function
Consider the function fx xxx A plot of this function for values of x between and is provided below.
The plot above shows that the function fx is equal to zero somewhere between x and x In other words, the
plot shows that the equation xxx has a solution somewhere between x and x Your goal in
this problem will be to approximate the value of this solution.
Perform the following steps in a single code cell:
Create variables x and x setting them equal to and respectively. We will use a loop to update the values
of these variables to close in on to the solution.
Create a variable named val setting it equal to the value you would obtain by plugging x into the function f
Create a variable named val setting it equal to the value you would obtain by plugging x into the function f
Notice that we can see from the plot that val should be negative and val should be positive.
Create a variable named n and set it equal to We will use this variable to count the number of iterations
required for the algorithm to converge to a solution.
Use a loop to iteratively update the values of the four variables above as described below. This loop should
continue to execute until the absolute value of val and val are both less than Each time the loop
executes, perform the following steps:
Increment n
Create a variable named newx that is equal to the average of x and x
Create a variable named newval that is equal to fnewx
If newval is negative, then set x to newx and set val to newval. Otherwise, set x to newx
and set val to newval.
When the loop is finished executing, x and x should be very near each other, and near to the solution. Take
the average of the two values to be the approximation for the solution. Print your result with a message as
shown below, with the xxxx strings replaced with the appropriate values. Round the approximate solution to
seven decimal places.
The approximate solution is x xxxx
The algorithm took xxxx iterations to converge.
No lists should be created for this problem, and only one loop should be used.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started