Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider a finite difference approximation D(x) to the first derivative of a function F, defined by arbitrary coefficients , , and , such that F(x)D(x)=(1/x)*(*F(xx)+*F(x)+*F(x+x))

Consider a finite difference approximation D(x) to the first derivative of a function F, defined by arbitrary coefficients , , and , such that

F(x)D(x)=(1/x)*(*F(xx)+*F(x)+*F(x+x))

Write a function derivative(f, x0, coeffs, dx) taking the arguments 'f' (a function), 'x0' (a number), 'coeffs' (a list of 3 numbers), and 'dx' (a positive number representing x), which computes and returns the finite difference approximation D(x0) to the first derivative of a generic function f at the point x0, where D(x) is defined as above.

The list 'coeffs' contains the 3 coefficients ,, in this order.

For example:

Test Result
import numpy as np def f(x): ''' Constant function f(x) = 0. ''' return np.zeros_like(x) d = derivative(f, 0, [0, -1, 1], 0.01) print(f'{abs(d):.6f}')
0.000000
import numpy as np def f(x): return x*x d = [derivative(f, 1, [-0.5, 0, 0.5], 0.01), derivative(f, 1, [-0.5, 0, 0.5], 0.1), derivative(f, 1, [-0.5, 0, 0.5], 0.5)] print(f'{d[0]:.6f}') print(f'{d[1]:.6f}') print(f'{d[2]:.6f}')
2.000000 2.000000 

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

Step: 3

blur-text-image

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago