Question: I ' m trying to use the following code to answer 4 numerical analysis questions. Each question should have its own cell and a visual

I'm trying to use the following code to answer 4 numerical analysis questions. Each question should have its own cell and a visual representation like the one screenshot. This is in python.
# The following code finds the forward, backward, and centered differencevalues, then plots the absolute errors on a log-Log scale plot.\import numpy as np
import matplotlib.pyplot as plt%matplotlib inlinePoint where derivative is evaluated
x=0.5
#function to be differentiated
f=np.exp(x)
#Derivative of function (theo. calculation)
fPrime=np.exp(x)
#get vector of deltax values
deltax =2.**np.arange(-1,-14,-1)#Compute forward approx.
fPlus = np.exp(x+deltax)
forward =(fPlus-f)/deltax
#Compute backward approx
fMinus = np.exp(x-deltax)
backward =(f-fMinus)/deltax
#use average of forward and backward for centered
centered =(forward + backward)}/
#compute absolute errors
forwardError = abs(fPrime - forward)
backwardError = abs(fPrime - backward)
centerError = abs(fPrime - centered)plt.figure(1)
#plot forward, backward, and centered errors on log-log scale
plt.plot(deltax, forwardError, label="Forward Difference")
plt.plot(deltax, backwardError, label="Backward Difference")
plt.plot(deltax, centerError, label="Centered Difference")plt.xlim([1,1e-4])
plt.ylim([1e-9,1])plt.xscale("log")
plt.yscale("log")plt.xlabel("Delta x")
plt.ylabel("Absolute Error") #Compute forward approx.
fPlus = np.exp(x+deltax)
forward =(fPlus-f)/deltax
#Compute backward approx
fMinus = np.exp(x-deltax)
backward =(f-fMinus)/deltax
#use average of forward and backward for centered
centered =(forward + backward)/2
#compute absolute errors
forwardError = abs(fPrime - forward)
backwardError = abs(fPrime - backward)
centerError = abs(fPrime - centered)plt.figure(1)
#plot forward, backward, and centered errors on log-log scale
plt.plot(deltax, forwardError, label="Forward Difference")
plt.plot(deltax, backwardError, label="Backward Difference")
plt.plot(deltax, centerError, label="Centered Difference")plt.xlim([1,1e-4])
plt.ylim([1e-9,1])plt.xscale("log")
plt.yscale("log")plt.xlabel("Delta x")
plt.ylabel("Absolute Error")plt. legend(loc=3)
plt.title("Errors for Fw, Bw, Ct Difference approx for f(x)=ex")
plt.show()
I ' m trying to use the following code to answer

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 Programming Questions!