Answered step by step
Verified Expert Solution
Question
1 Approved Answer
using python, juyper notebook of 6 - ZOOM Problem 6: Finding a Root of a Polynomial Function Consider the function f(x) = x2 - 4x2
using python, juyper notebook
of 6 - ZOOM Problem 6: Finding a Root of a Polynomial Function Consider the function f(x) = x2 - 4x2 + 3x 4. A plot of this function for values of x between 0 and 5 is provided below. 30 20 30 The plot above shows that the function f (x) is equal to zero somewhere between r = 0 and x = 5. In other words, the plot shows that the equation - 122 + 3x - 1 - 0 has a solution somewhere between x = 0 and x = 5. Your goal in this problem will be to approximate the value of this solution. Perform the following steps in a single code cell: 1. Create variables xi and x2, setting them equal to 0 and 5, respectively. We will use a loop to update the values of these variables to close in on to the solution. 2. Create a variable named val, setting it equal to the value you would obtain by plugging x1 into the function f. Create a variable named val2, setting it equal to the value you would obtain by plugging x2 into the function f. Notice that we can see from the plot that vali should be negative and valz should be positive. 3. Create a variable named n and set it equal to 0. 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 val1 and val2 are both less than 0.000001. Each time the loop executes, perform the following steps: Increment n. Create a variable named new_x that is equal to the average of 1 and 2 Create a variable named new_val that is equal to f(new_x). If new_val is negative, then set x1 to new_x and set vali to new_val. Otherwise, set x2 to new_x and set val2 to new_val 5. When the loop is finished executing, xi and x2 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. > of 6 - ZOOM The plot above shows that the function f(x) is equal to zero somewhere between x-O and x - 5. In other words, the plot shows that the equation x - 4x + 3x - 4 = 0 has a solution somewhere between x = 0 and x = 5. Your goal in this problem will be to approximate the value of this solution. Perform the following steps in a single code cell: 1. Create variables x1 and 2, setting them equal to 0 and 5, respectively. We will use a loop to update the values of these variables to close in on to the solution 2. Create a variable named vali, setting it equal to the value you would obtain by plugging x1 into the function f. Create a variable named va12, setting it equal to the value you would obtain by plugring x2 into the function f. Notice that we can see from the plot that val1 should be negative and val2 should be positive. 3. Create a variable named n and set it equal to 0. 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 vali and val2 are both less than 0.000001. Each time the loop executes, perform the following steps: Increment n. Create a variable named new_x that is equal to the average of 1 and 2 Create a variable named new_val that is equal to f(new_x). If new_val is negative, then set x1 to new_x and set vali to new_val. Otherwise, set x2 to new_x and set val2 to new_val 5. When the loop is finished executing, x1 and x2 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 usedStep 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