Question: Consider the finite interval I = [-a, a] with a = 5 on the real axis. Define N + 1 equally spaced grid-points x
Consider the finite interval I = [-a, a] with a = 5 on the real axis. Define N + 1 equally spaced grid-points x = a+ih, i=0,..., N spanning I (i.e., xXN = a). Investigate the functions on I. g(x) = exp(-2) and h(x) = sin(x), a) Define h. Plot these functions within the interval I by defining these functions on the grid-points x for a reasonable N. b) Plot the first derivative of these functions obtained analytically. (use same discretization and N) c) Calculate and plot the first derivatives of these functions by employing the first order backward, forward, and central difference derivatives. (Hand in code). Pay attention to the cases i = 0 and i = N. d) Find the smallest value of N for each method and function, such that the relative error of numerical and analytical derivative is less than 1%. e) Calculate and plot the second derivative numerically using central differences (see chapter 2.4) for h(x) and find a suitable N such that the relative error is less than 1%.
Step by Step Solution
There are 3 Steps involved in it
import numpy as np import matplotlibpyplot as plt def gx return npexpx2 def hx return npsinx def gderivativex return 2xnpexpx2 def hderivativex return npcosx def hsecondderivativex return npsinx Defin... View full answer
Get step-by-step solutions from verified subject matter experts
