Is there a calculus library for JavaScript?

Does anyone know a Calculus library for JavaScript? I did a few googling and came up with nothing. I applied for the WolframAlpha API, but it’s expensive if they don’t want to give me a grant.

Ideally, I could pass an array of 2d points to a function and return the graph (array) of points of the derivative.

If such a library does not exist, I will create it for sharing.

+6
javascript math calculus
source share
1 answer

Since you say that you have a 2-D array of points, I assume that you have a function of two variables f(x, y) . This means that you do not have a single derivative. Instead, you get a set of private derivatives.

You can approximate partial derivatives using finite difference formulas.

The partial derivative with x to x for f(x, y) is (f(x+h, y) - f(xh, y))/2h .

The partial derivative with respect to y for f(x, y) is (f(x, y+h) - f(x, yh))/2h .

In these formulas, h is the space between the nodes on your grid, if you have a grid with regular spacing. If the horizontal and vertical distances are different, use the horizontal distance for partial with respect to x and the vertical distance for partial with respect to y .

Update . I misunderstood your question. I thought a 2-D array is an array of domain values. If you have a list of x and f(x) , you can approach f'(x) as (f(x+h) - f(xh)) / 2h . This will work everywhere except the first and last, where one of the conditions will be out of range. You can use (f(x + h) - f(x))/h at the left end and (f(x) - f(xh))/h at the right end. At endpoints, the approximation will be less accurate, but this cannot be avoided.

+5
source share

All Articles