Central difference formula is used to approximate the derivative of a function. Here is a simple implementation of central difference formula in Javascript:
index.tsx91 chars4 lines
Where x
is the point at which the derivative is to be approximated, h
is the step size and func
is the function for which the derivative is to be approximated.
Here is an example of how to use this function:
index.tsx189 chars9 lines
In this example, the derivative of the cos
function is approximated at x=1
using the centralDifference
function. The result is logged to the console.
gistlibby LogSnag