是否有针对JavaScript的微积分库? [英] Is there a Calculus library for JavaScript?
问题描述
有没有人知道JavaScript的微积分库?我做了一些谷歌搜索并没有想出任何东西。我申请了WolframAlpha API,但除非他们选择给我一笔赠款,否则价格昂贵。
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.
理想情况下,我可以将2d点数组输入函数中,然后获取返回导数点的图(阵列)。
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.
推荐答案
既然你说你有一个2-D点数组,我假设你有两个变量函数 f(x,y)
。这意味着你没有单一衍生品。相反,你得到一组偏导数。
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.
f
x
的偏导数将是(f (x + h,y) - f(xh,y))/ 2h
。
关于<$ c $的偏导数c> y at f(x,y)
将是(f(x,y + h) - f( x,yh))/ 2h
。
在这些公式中, h
是假设您有一个规则间隔的网格,网格上节点之间的空间。如果水平和垂直间距不同,则使用相对于 x
的部分的水平间距和相对于 y的部分的垂直间距
。
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
.
更新:我误解了你的问题。我以为二维数组是一个域值数组。如果您有 x
和 f(x)
值的列表,则可以近似 f '(x)
as (f(x + h) - f(xh))/ 2h
。除了在其中一个术语超出范围的第一个和最后一个点之外,这将在任何地方都有效。您可以在左端使用(f(x + h) - f(x))/ h
和(f(x) - f( xh))/ h
在右端。在终点处近似值不太准确,但无法避免。
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.
这篇关于是否有针对JavaScript的微积分库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!