开发者

Is there a Calculus library for JavaScript? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 6 years ago.

开发者_运维知识库 Improve this question

Does anyone know of a Calculus library for JavaScript? I've done some Googling and haven't come up with anything. I applied for the WolframAlpha API, but that's expensive unless they choose to give me a grant.

Ideally, I could feed an Array of 2d points into a function, and get back the graph (Array) of points of the derivative.

If such a library does not exist, I will create one to share.


Since you say you have a 2-D array of points, I assume you have a function of two variables f(x, y). That means you don't have a single derivative. Instead you get a set of partial derivatives.

You could approximate the partial derivatives using finite difference formulas.

The partial derivative with respect to x at f(x, y) would be (f(x+h, y) - f(x-h, y))/2h.

The partial derivative with respect to y at f(x, y) would be (f(x, y+h) - f(x, y-h))/2h.

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

Update: I misunderstood your question. I thought the 2-D array was an array of domain values. If you have a list of x and f(x) values, you can approximate f'(x) as (f(x+h) - f(x-h)) / 2h. This will work everywhere except at the first and last points where one of the terms will be out of range. You can use (f(x + h) - f(x))/h at the left end and (f(x) - f(x-h))/h at the right end. The approximation will be less accurate at the end points but that can't be avoided.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜