calcBasisFunctionDerivatives function
dynamic
calcBasisFunctionDerivatives(
- dynamic span,
- dynamic u,
- dynamic p,
- dynamic n,
- dynamic U,
Implementation
calcBasisFunctionDerivatives(span, u, p, n, U) {
var zeroArr = [];
for (var i = 0; i <= p; ++i) {
zeroArr[i] = 0.0;
}
var ders = [];
for (var i = 0; i <= n; ++i) {
ders[i] = zeroArr.sublist(0);
}
var ndu = [];
for (var i = 0; i <= p; ++i) {
ndu[i] = zeroArr.sublist(0);
}
ndu[0][0] = 1.0;
var left = zeroArr.sublist(0);
var right = zeroArr.sublist(0);
for (var j = 1; j <= p; ++j) {
left[j] = u - U[span + 1 - j];
right[j] = U[span + j] - u;
var saved = 0.0;
for (var r = 0; r < j; ++r) {
var rv = right[r + 1];
var lv = left[j - r];
ndu[j][r] = rv + lv;
var temp = ndu[r][j - 1] / ndu[j][r];
ndu[r][j] = saved + rv * temp;
saved = lv * temp;
}
ndu[j][j] = saved;
}
for (var j = 0; j <= p; ++j) {
ders[0][j] = ndu[j][p];
}
for (var r = 0; r <= p; ++r) {
var s1 = 0;
var s2 = 1;
var a = [];
for (var i = 0; i <= p; ++i) {
a[i] = zeroArr.sublist(0);
}
a[0][0] = 1.0;
for (var k = 1; k <= n; ++k) {
var d = 0.0;
var rk = r - k;
var pk = p - k;
if (r >= k) {
a[s2][0] = a[s1][0] / ndu[pk + 1][rk];
d = a[s2][0] * ndu[rk][pk];
}
var j1 = (rk >= -1) ? 1 : -rk;
var j2 = (r - 1 <= pk) ? k - 1 : p - r;
for (var j = j1; j <= j2; ++j) {
a[s2][j] = (a[s1][j] - a[s1][j - 1]) / ndu[pk + 1][rk + j];
d += a[s2][j] * ndu[rk + j][pk];
}
if (r <= pk) {
a[s2][k] = -a[s1][k - 1] / ndu[pk + 1][r];
d += a[s2][k] * ndu[r][pk];
}
ders[k][r] = d;
var j = s1;
s1 = s2;
s2 = j;
}
}
var r = p;
for (var k = 1; k <= n; ++k) {
for (var j = 0; j <= p; ++j) {
ders[k][j] *= r;
}
r *= p - k;
}
return ders;
}