Question: Please help with this Python problem. I need to round to significant figures and check for error! I have attached the code that I need

Please help with this Python problem. I need to round to significant figures and check for error! I have attached the code that I need help rounding and errors and the specific question. Please please help!

import numpy as np from matplotlib import pyplot as plt from numpy import cos,sin

def f_1(x): return 10 - 2*x + sin(x)

def Df_1(x): return -2 + cos(x)

def newton (f, Df, x0, errorTolerance, maxIterations = 100, demoMode = False): if demoMode: print("Solving by Newton's Morthod.") functionEvaluations = 0 x = x0 for iterations in range(1, maxIterations + 1): fx = f(x) Dfx = Df(x) functionEvaluations += 2 dx = fx/Dfx x -= dx errorEstimate = abs(dx) if demoMode: print(f"{iterations=}, {x=} with estimate error {errorEstimate:0.3}, backward error {abs(f(x)):0.3}") if errorEstimate <= errorTolerance: break return (x, errorEstimate, iterations, functionEvaluations)

def bisection(f,a,b,errorTolerance,maxIterations=100,demoMode=False): if demoMode: print("Solving by the Bisection Method.") functionEvaluations = 0 fa = f(a) functionEvaluations += 1 for iteration in range(1, maxIterations): c = (a+b)/2 fc = f(c) functionEvaluations += 1 if fa * fc < 0: b = c else: a = c fa = fc errorBound = (b-a)/2 if demoMode: print(f"{iteration=}, approximate root {c}, {errorBound=:0.3}") if errorBound <= errorTolerance: break root = c return (root, errorBound, iteration, functionEvaluations)

def secant (f, a, b, errorTolerance, maxIterations = 100, demoMode=False): if demoMode: print("Solving by the Bisection Method.") functionEvaluations = 0 fa = f(a) functionEvaluations += 1 for iteration in range(1, maxIterations): c = (a+b)/2 fc = f(c) functionEvaluations += 1 if fa * fc < 0: b = c else: a = c fa = fc errorBound = (b-a)/2 if demoMode: print(f"{iteration=}, approximate root {c}, {errorBound=:0.3}") if errorBound <= errorTolerance: break root = c return (root, errorBound, iteration, functionEvaluations)

a = 0 b = 5 x = np.linspace(a,b) plt.figure(figsize=[12, 8]) plt.title(f"$y = f_1(x) = 10 - 2x + \sin(x)$") plt.plot(x, f_1(x)) plt.grid(True)

(root, errorEstimate, iterations, functionEvaluations) = newton(f_1, Df_1, x0=4, errorTolerance=1e-6,demoMode=True) print(" ") print(f"{root=}, {errorEstimate=:0.3}, {iterations=}, {functionEvaluations=}") print(f"P.S. the backward error is {abs(f_1(root)):0.3}")

(root, errorBound, iterations, functionEvaluations) = bisection(f_1,a=0,b=5,errorTolerance=1e-6,demoMode=True) print(" ") print(f"{root=}, {errorBound=:0.3}, {iterations=}, {functionEvaluations=}") print(f"P.S. the backward error is {abs(f_1(root)):0.3}")

(root, errorEstimate, iterations, functionEvaluations) = secant(f_1, a=0, b=5, errorTolerance=1e-6, maxIterations=100, demoMode=True) print(" ") print(f"{root=}, {errorEstimate=:0.3}, {iterations=}, {functionEvaluations=}") print(f"P.S. the backward error is {abs(f_1(root)):0.3}")

A) For =8.024 and =8.006

  • Round each to three significant figures, giving and .
  • Compute the absolute errors in each of these approximations, and in their difference as an approximation of .
  • Compute the relative errors in each of these three approximations.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!