int j = 0; for (double i = from; i < to; i+=delta) { values[j] = getFunctionValue(f, index, i); j++; values[j] = getFunctionValue(f, index, to); } else if ( (to <= from) && (delta < 0) ) { for (double i = from; i > to; i+=delta) int j = 0; for (double i = from; i > to; i+=delta) { values[j] = getFunctionValue(f, index, i); j++; values[j] = getFunctionValue(f, index, to); } else if (from == to) { n = 1; values = new double[n]; values[0] = getFunctionValue(f, index, from); } else values = null; return values;
double dy = 0.0; if ( (derType == LEFT_DERIVATIVE) || (derType == RIGHT_DERIVATIVE) ) { y0 = mXparser.getFunctionValue(f, x, x0); dy = mXparser.getFunctionValue(f, x, x0+dx) - y0; derF = dy/dx; } else derF = ( mXparser.getFunctionValue(f, x, x0+dx) - mXparser.getFunctionValue(f, x, x0-dx) ) / (2.0*dx); do { derFprev = derF; dx = dx/2.0; if ( (derType == LEFT_DERIVATIVE) || (derType == RIGHT_DERIVATIVE) ) { dy = mXparser.getFunctionValue(f, x, x0+dx) - y0; derF = dy/dx; } else derF = ( mXparser.getFunctionValue(f, x, x0+dx) - mXparser.getFunctionValue(f, x, x0-dx) ) / (2.0*dx); error = Math.abs(derF - derFprev); step++;
for (i = from; i < to; i+=delta) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; result += mXparser.getFunctionValue(f, index, i); if ( delta - (i - to) > 0.5 * delta) result += mXparser.getFunctionValue(f, index, to); } else if ( (to <= from) && (delta < 0) ) { double i; for (i = from; i > to; i+=delta) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; result += mXparser.getFunctionValue(f, index, i); result += mXparser.getFunctionValue(f, index, to); } else if (from == to) result += mXparser.getFunctionValue(f, index, from); return result;
for (double i = from; i < to; i+=delta) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; v = mXparser.getFunctionValue(f, index, i); if (v > max) max = v; v = mXparser.getFunctionValue(f, index, to); if (v > max) max = v; } else if ( (to <= from) && (delta < 0) ) { for (double i = from; i > to; i+=delta) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; v = mXparser.getFunctionValue(f, index, i); if (v > max) max = v; v = mXparser.getFunctionValue(f, index, to); if (v > max) max = v; } else if (from == to) max = mXparser.getFunctionValue(f, index, from); return max;
for (i = from; i < to; i+=delta) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; result *= mXparser.getFunctionValue(f, index, i); if ( delta - (i - to) > 0.5 * delta) result *= mXparser.getFunctionValue(f, index, to); } else if ( (to <= from) && (delta < 0) ) { double i; for (i = from; i > to; i+=delta) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; result *= mXparser.getFunctionValue(f, index, i); if ( -delta - (to - i) > -0.5 * delta) result *= mXparser.getFunctionValue(f, index, to); } else if (from == to) result *= mXparser.getFunctionValue(f, index, from); return result;
/** * Backward difference(1) operator (at x = x0). * * @param f the expression * @param x the argument name * @param x0 x = x0 * * @return Backward difference value calculated at x0. * * @see Expression * @see Argument */ public static final double backwardDifference(Expression f, Argument x, double x0) { if (Double.isNaN(x0)) return Double.NaN; double xb = x.getArgumentValue(); double delta = mXparser.getFunctionValue(f, x, x0) - mXparser.getFunctionValue(f, x, x0-1); x.setArgumentValue(xb); return delta; } /**
for (double i = from; i < to; i+=delta) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; v = mXparser.getFunctionValue(f, index, i); if (v < min) min = v; v = mXparser.getFunctionValue(f, index, to); if (v < min) min = v; } else if ( (to <= from) && (delta < 0) ) { for (double i = from; i > to; i+=delta) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; v = mXparser.getFunctionValue(f, index, i); if (v < min) min = v; v = mXparser.getFunctionValue(f, index, to); if (v < min) min = v; } else if (from == to) min = mXparser.getFunctionValue(f, index, from); return min;
/** * Backward difference(h) operator (at x = x0) * * @param f the expression * @param h the difference * @param x the argument name * @param x0 x = x0 * * @return Backward difference(h) value calculated at x0. * * @see Expression * @see Argument */ public static final double backwardDifference(Expression f, double h, Argument x, double x0) { if (Double.isNaN(x0)) return Double.NaN; double xb = x.getArgumentValue(); double delta = mXparser.getFunctionValue(f, x, x0) - mXparser.getFunctionValue(f, x, x0-h); x.setArgumentValue(xb); return delta; } /**
/** * Forward difference(1) operator (at x = x0) * * @param f the expression * @param x the argument name * @param x0 x = x0 * * @return Forward difference(1) value calculated at x0. * * @see Expression * @see Argument */ public static final double forwardDifference(Expression f, Argument x, double x0) { if (Double.isNaN(x0)) return Double.NaN; double xb = x.getArgumentValue(); double delta = mXparser.getFunctionValue(f, x, x0+1) - mXparser.getFunctionValue(f, x, x0); x.setArgumentValue(xb); return delta; } /**
double eps, int maxSteps) { double h = 0.5*(b-a); double s = mXparser.getFunctionValue(f, x, a) + mXparser.getFunctionValue(f, x, b) + 2 * mXparser.getFunctionValue(f, x, a + h); double intF = s*h*0.5; double intFprev = 0; for (j = 1; j <= n; j++) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; s += 2 * mXparser.getFunctionValue(f, x, t); t += h;
/** * Forward difference(h) operator (at x = x0) * * @param f the expression * @param h the difference * @param x the argument name * @param x0 x = x0 * * @return Forward difference(h) value calculated at x0. * * @see Expression * @see Argument */ public static final double forwardDifference(Expression f, double h, Argument x, double x0) { if (Double.isNaN(x0)) return Double.NaN; double xb = x.getArgumentValue(); double delta = mXparser.getFunctionValue(f, x, x0+h) - mXparser.getFunctionValue(f, x, x0); x.setArgumentValue(xb); return delta; } /**
for (i = from; i < to; i+=delta) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; sum += mXparser.getFunctionValue(f, index, i); n++; sum += mXparser.getFunctionValue(f, index, to); n++; for (i = from; i > to; i+=delta) { if (mXparser.isCurrentCalculationCancelled()) return Double.NaN; sum += mXparser.getFunctionValue(f, index, i); n++; sum += mXparser.getFunctionValue(f, index, to); n++; return mXparser.getFunctionValue(f, index, from); return sum / n;
if (derType == RIGHT_DERIVATIVE) for (int i = 1; i <= n; i++) derF += MathFunctions.binomCoeff(-1,n-i) * MathFunctions.binomCoeff(n,i) * mXparser.getFunctionValue(f,x,x0+i*dx); else for (int i = 1; i <= n; i++) derF += MathFunctions.binomCoeff(-1,i)*MathFunctions.binomCoeff(n,i) * mXparser.getFunctionValue(f,x,x0-i*dx); derF = derF / Math.pow(dx, n); do { if (derType == RIGHT_DERIVATIVE) for (int i = 1; i <= n; i++) derF += MathFunctions.binomCoeff(-1,n-i) * MathFunctions.binomCoeff(n,i) * mXparser.getFunctionValue(f,x,x0+i*dx); else for (int i = 1; i <= n; i++) derF += MathFunctions.binomCoeff(-1,i)*MathFunctions.binomCoeff(n,i) * mXparser.getFunctionValue(f,x,x0-i*dx); derF = derF / Math.pow(dx, n); error = Math.abs(derF - derFprev);
b = tmp; fa = mXparser.getFunctionValue(f, x, a); fb = mXparser.getFunctionValue(f, x, b); bp = tmp; fa = mXparser.getFunctionValue(f, x, ap); fb = mXparser.getFunctionValue(f, x, bp); if (MathFunctions.abs(fa) <= eps) return ap; if (MathFunctions.abs(fb) <= eps) return bp; fc = mXparser.getFunctionValue(f, x, c); if (MathFunctions.abs(fa) < MathFunctions.abs(fb)) { tmp = a; } else mflag = true; fs = mXparser.getFunctionValue(f, x, s); d = c; c = b;