Question: Could someone help me write a python script to plot the forward, backward, and central finite difference (FD) of the first order, and second order

Could someone help me write a python script to plot the forward, backward, and central finite difference (FD) of the first order, and second order derivatives of any input smooth function f(x).

def FD_1st_order(f, x, h=1e-4, fder=None, filename=None): '''compute 1st order derivative of f(x) using FFD, CFD, BFD. tasks: (1) output f'(x) in a tuple named (ffd, cfd, bfd), where ffd, cfd, bfd store the f'(x) obtained by FFD, CFD, and BFD; (2) call FD_plot() to do the plotting: (2.1) when exact f'(x) is passed as input via fder, need to pass it on so that a curve of exact dervative will be plotted in addition to FD curves (2.2) when filename is passed as input, need to pass it on so that the plot will be saved to a png file using a modification of this filename ''' #add code to make sure elementwise operations such as x+h and x-h are valid for x x =

#add code to compute 1st order ffd, bfd, cfd ffd= bfd= cfd=

#add code to call FD_plot(), for the 1st order, this is done for you below FD_plot(x, h, ffd, cfd, bfd, fderivative=fder, FD_order='1st', filename=filename)

return (ffd, cfd, bfd)

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