Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q 2 : In this question, you will use Python to perform numerical differentiation the function f ( x ) = e 3 x .
Q: In this question, you will use Python to perform numerical differentiation the function
Follow these steps:
Create an array named containing evenly spaced values ranging from to
These values will serve as the step sizes for the numerical differentiation. See hint at the
end of the question.
For each step size in calculate the forward difference approximation of at
Then, determine the percentage of the absolute relative error for each step size. Plot this
percentage against the values in and include the plot in your report.
Repeat the process for the backward difference approximation of at
Calculate the percentage of the absolute relative error for each step size in and plot
these percentages against Include this plot in your report.
Do the same for the centred difference approximation of at Calculate the
percentage of the absolute relative error for each step size in and plot these
percentages against This plot should also be included in your report.
Analyse and discuss what happens to the error as the step size decreases.
Compare the three methods and determine which approximation is the most accurate.
Include the Python code used for these steps in your report.
Hint:
import matplotlib.pyplot as plt
import numpy as
def :
return exp
# Derivative of the function
def :
return
# Create an array H with numbers evenly distributed between and
inspace
# Exact derivative at
exactderivative
# Forward difference approximation
forwarddiff
# Calculate the percentage of the absolute relative error
forwarderror npabsforwarddiff exactderivative
Step 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