Question: Please write down the python code and screen capture the results. Thank you! Q2: In this question, you will use Python to numerically differentiate the

Please write down the python code and screen capture the results. Thank you!
Q2: In this question, you will use Python to numerically differentiate the function f(x) = 22x. 1- Create an array of 100 equally spaced numbers between 0.001 and 0.5 and name it H. Each element in H will be a step-size for the numerical differentiation. See the hint at the end. 2- Compute the forward difference approximation of f(x) at x; = 0 for every step-size in H. Compute the percentage of the absolute value of relative error of forward difference approximation for every step-size in H. + t t = t t Plot the percentage of relative error versus H. Include the plot in your report. 3- Compute the backward difference approximation of f(x) at xi o for every step-size in H. 4- Compute the percentage of the absolute value of relative error of backward difference approximation for every step-size in H. + Plot the percentage of relative error versus H. Include the plot in your report. + 5- Compute the centred difference approximation of f(x) at x; = 0 for every step-size in H. + Compute the percentage of the absolute value of relative error of centred difference approximation for every step-size in H. Plot the percentage of relative error versus H. Include the plot in your report. + 6- What will happen as the step-size decreases? 7- Which approximation is more accurate? t t + + Include your code in your report. Hint: import numpy as np import matplotlib.pyplot as plt- H=np.linspace(0.001, 0.5, 100);#creates an array of equally spaced between 0.001 and 0.5 FM=np.zeros(100);#creates an array of 100 zeros. BM=np.zeros(100);#creates an array of 100 zeros. CM=np.zeros(100);#creates an array of 100 zeros. for in range(0,100):- FM[i]= #write your code for computing the forward approximation for step-size H[i]- BM[i]= #write your code for computing the backward approximation for step-size H[i]- CM[i]= #write your code for computing the centred approximation for step-size H[i]+ Q2: In this question, you will use Python to numerically differentiate the function f(x) = 22x. 1- Create an array of 100 equally spaced numbers between 0.001 and 0.5 and name it H. Each element in H will be a step-size for the numerical differentiation. See the hint at the end. 2- Compute the forward difference approximation of f(x) at x; = 0 for every step-size in H. Compute the percentage of the absolute value of relative error of forward difference approximation for every step-size in H. + t t = t t Plot the percentage of relative error versus H. Include the plot in your report. 3- Compute the backward difference approximation of f(x) at xi o for every step-size in H. 4- Compute the percentage of the absolute value of relative error of backward difference approximation for every step-size in H. + Plot the percentage of relative error versus H. Include the plot in your report. + 5- Compute the centred difference approximation of f(x) at x; = 0 for every step-size in H. + Compute the percentage of the absolute value of relative error of centred difference approximation for every step-size in H. Plot the percentage of relative error versus H. Include the plot in your report. + 6- What will happen as the step-size decreases? 7- Which approximation is more accurate? t t + + Include your code in your report. Hint: import numpy as np import matplotlib.pyplot as plt- H=np.linspace(0.001, 0.5, 100);#creates an array of equally spaced between 0.001 and 0.5 FM=np.zeros(100);#creates an array of 100 zeros. BM=np.zeros(100);#creates an array of 100 zeros. CM=np.zeros(100);#creates an array of 100 zeros. for in range(0,100):- FM[i]= #write your code for computing the forward approximation for step-size H[i]- BM[i]= #write your code for computing the backward approximation for step-size H[i]- CM[i]= #write your code for computing the centred approximation for step-size H[i]+
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
