Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q 2 : In this question, you will use Python to perform numerical differentiation the function f ( x ) = e 3 x .

Q2: In this question, you will use Python to perform numerical differentiation the function
f(x)=e3x. Follow these steps:
Create an array named H containing 100 evenly spaced values ranging from 0.001 to 0.5.
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 H, calculate the forward difference approximation of f(x) at xi=0.
Then, determine the percentage of the absolute relative error for each step size. Plot this
percentage against the values in H and include the plot in your report.
Repeat the process for the backward difference approximation of f(x) at xi=0.
Calculate the percentage of the absolute relative error for each step size in H and plot
these percentages against H. Include this plot in your report.
Do the same for the centred difference approximation of f(x) at xi=0). Calculate the
percentage of the absolute relative error for each step size in H and plot these
percentages against H. 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 np
def f(x) :
return np.exp(3**x)
# Derivative of the function
def df(x) :
return 3**np*exp(3**x)
# Create an array H with 100 numbers evenly distributed between 0.001 and 0.5
H=np. inspace (0.001,0.5,100)
# Exact derivative at x=0
exact_derivative =df()
# Forward difference approximation
forward_diff =f(H)-f()H
...
# Calculate the percentage of the absolute relative error
forward_error = np.abs((forward_diff - exact_derivative
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

Students also viewed these Databases questions