Question: Consider the function f ( x ) = x 3 - 4 x 2 + 3 x - 4 . A plot of this function
Consider the function A plot of this function for values of between and is provided below.
The plot above shows that the function is equal to zero somewhere between and In other words, the
plot shows that the equation has a solution somewhere between and 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 and 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 into the function
Create a variable named val setting it equal to the value you would obtain by plugging into the function
Notice that we can see from the plot that val should be negative and val should be positive.
Create a variable named 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
Create a variable named newx that is equal to the average of and
Create a variable named newval that is equal to new
If newval is negative, then set to new and set val to newval. Otherwise, set to newx
and set val to newval.
When the loop is finished executing, and 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 strings replaced with the appropriate values. Round the approximate solution to
seven decimal places.
The approximate solution is
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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
