我正在开发一个网络软件,用JSXGraph绘制一个带有2个变量的交互式多项式方程,我需要方程的导数为0的每个点都有一个可拖动的点,当我拖动一个点时,只有在曲线的拖动点之前1点和1点之间的间隔合在一起有没有人知道我该怎么做?
答案 0 :(得分:0)
抱歉延误。我想,你需要的是 Hermite插值。我最近在Google网上论坛(https://groups.google.com/forum/#!topic/jsxgraph/OHls2NTOmUA)举了一个例子。 Hermite插值尚未集成在JSXGraph中,但似乎需要它,所以我们可以考虑它。
以下是代码:
JXG.Math.Numerics.hermitePolynomial = function (p, derivatives) {
var w = [],
Lii = [],
/** @ignore */
fct = function (x, suspendedUpdate) {
var i, k, xi, s,
L, Hi, Hi_hat,
len = p.length,
num = 0,
denom = 0;
if (!suspendedUpdate) {
// Compute denominator
for (i = 0; i < len; i++) {
w[i] = 1.0;
Lii[i] = 0.0;
xi = p[i].X();
for (k = 0; k < len; k++) {
if (k !== i) {
w[i] *= (xi - p[k].X());
Lii[i] += 1 / (xi - p[k].X());
}
}
w[i] = 1 / w[i];
}
}
s = 0.0;
for (i = 0; i < len; i++) {
xi = p[i].X();
L = w[i];
for (k = 0; k < len; k++) {
if (k !== i) {
L *= (x - p[k].X());
}
}
Hi = (1.0 - 2 * (x - xi) * Lii[i]) * L * L;
Hi_hat = (x -xi) * L * L;
s += p[i].Y() * Hi + derivatives[i] * Hi_hat;
}
return s;
};
return fct;
};
var board = JXG.JSXGraph.initBoard("jxgbox", {
boundingbox: [-5, 6, 6, -5],
axis: true
});
var p = [];
// Define the points
p[0] = board.create('point', [-1,2], {size:4});
p[1] = board.create('point', [1,-2], {size:4});
p[2] = board.create('point', [3,-1], {size:4});
// The derivates at this points are all zero.
var derivatives = [0, 0, 0];
var f = JXG.Math.Numerics.hermitePolynomial(p, derivatives);
var graph = board.create('functiongraph', [f, -10, 10], {strokeWidth:2});
现场演示位于https://jsfiddle.net/vcL7aepo/278/
祝福, 阿尔弗雷德