当前位置: 首页>>代码示例>>Java>>正文


Java UnivariateRealFunction.value方法代码示例

本文整理汇总了Java中org.apache.commons.math.analysis.UnivariateRealFunction.value方法的典型用法代码示例。如果您正苦于以下问题:Java UnivariateRealFunction.value方法的具体用法?Java UnivariateRealFunction.value怎么用?Java UnivariateRealFunction.value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math.analysis.UnivariateRealFunction的用法示例。


在下文中一共展示了UnivariateRealFunction.value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: stage

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
 * Compute the n-th stage integral of trapezoid rule. This function
 * should only be called by API <code>integrate()</code> in the package.
 * To save time it does not verify arguments - caller does.
 * <p>
 * The interval is divided equally into 2^n sections rather than an
 * arbitrary m sections because this configuration can best utilize the
 * alrealy computed values.</p>
 *
 * @param f the integrand function
 * @param min the lower bound for the interval
 * @param max the upper bound for the interval
 * @param n the stage of 1/2 refinement, n = 0 is no refinement
 * @return the value of n-th stage integral
 * @throws FunctionEvaluationException if an error occurs evaluating the
 * function
 */
double stage(final UnivariateRealFunction f,
             final double min, final double max, final int n)
    throws FunctionEvaluationException {
    
    long i, np;
    double x, spacing, sum = 0;
    
    if (n == 0) {
        s = 0.5 * (max - min) * (f.value(min) + f.value(max));
        return s;
    } else {
        np = 1L << (n-1);           // number of new points in this stage
        spacing = (max - min) / np; // spacing between adjacent new points
        x = min + 0.5 * spacing;    // the first new point
        for (i = 0; i < np; i++) {
            sum += f.value(x);
            x += spacing;
        }
        // add the new sum to previously calculated result
        s = 0.5 * (s + sum * spacing);
        return s;
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:41,代码来源:TrapezoidIntegrator.java

示例2: sample

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
 * Sample the given univariate real function on the given interval.
 * <p>
 * The interval is divided equally into N sections and sample points
 * are taken from min to max-(max-min)/N. Usually f(x) is periodic
 * such that f(min) = f(max) (note max is not sampled), but we don't
 * require that.</p>
 *
 * @param f the function to be sampled
 * @param min the lower bound for the interval
 * @param max the upper bound for the interval
 * @param n the number of sample points
 * @return the samples array
 * @throws FunctionEvaluationException if function cannot be evaluated
 * at some point
 * @throws IllegalArgumentException if any parameters are invalid
 */
public static double[] sample(UnivariateRealFunction f,
                              double min, double max, int n)
    throws FunctionEvaluationException, IllegalArgumentException {

    if (n <= 0) {
        throw MathRuntimeException.createIllegalArgumentException(
                "number of sample is not positive: {0}",
                n);
    }
    verifyInterval(min, max);

    double s[] = new double[n];
    double h = (max - min) / n;
    for (int i = 0; i < n; i++) {
        s[i] = f.value(min + i * h);
    }
    return s;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:36,代码来源:FastFourierTransformer.java

示例3: solve

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
 * Find a real root in the given interval with initial value.
 * <p>
 * Requires bracketing condition.</p>
 *
 * @param f the function to solve
 * @param min the lower bound for the interval
 * @param max the upper bound for the interval
 * @param initial the start value to use
 * @return the point at which the function value is zero
 * @throws MaxIterationsExceededException if the maximum iteration count is exceeded
 * or the solver detects convergence problems otherwise
 * @throws FunctionEvaluationException if an error occurs evaluating the
 * function
 * @throws IllegalArgumentException if any parameters are invalid
 */
public double solve(final UnivariateRealFunction f,
                    final double min, final double max, final double initial)
    throws MaxIterationsExceededException, FunctionEvaluationException {

    // check for zeros before verifying bracketing
    if (f.value(min) == 0.0) { return min; }
    if (f.value(max) == 0.0) { return max; }
    if (f.value(initial) == 0.0) { return initial; }

    verifyBracketing(min, max, f);
    verifySequence(min, initial, max);
    if (isBracketing(min, initial, f)) {
        return solve(f, min, initial);
    } else {
        return solve(f, initial, max);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:34,代码来源:MullerSolver.java

示例4: sample

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
 * Sample the given univariate real function on the given interval.
 * <p>
 * The interval is divided equally into N sections and sample points
 * are taken from min to max-(max-min)/N. Usually f(x) is periodic
 * such that f(min) = f(max) (note max is not sampled), but we don't
 * require that.</p>
 *
 * @param f the function to be sampled
 * @param min the lower bound for the interval
 * @param max the upper bound for the interval
 * @param n the number of sample points
 * @return the samples array
 * @throws MathUserException if function cannot be evaluated at some point
 * @throws IllegalArgumentException if any parameters are invalid
 */
public static double[] sample(UnivariateRealFunction f, double min, double max, int n)
    throws MathUserException, IllegalArgumentException {

    if (n <= 0) {
        throw MathRuntimeException.createIllegalArgumentException(
                LocalizedFormats.NOT_POSITIVE_NUMBER_OF_SAMPLES,
                n);
    }
    verifyInterval(min, max);

    double s[] = new double[n];
    double h = (max - min) / n;
    for (int i = 0; i < n; i++) {
        s[i] = f.value(min + i * h);
    }
    return s;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:34,代码来源:FastFourierTransformer.java

示例5: stage

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
 * Compute the n-th stage integral of trapezoid rule. This function
 * should only be called by API <code>integrate()</code> in the package.
 * To save time it does not verify arguments - caller does.
 * <p>
 * The interval is divided equally into 2^n sections rather than an
 * arbitrary m sections because this configuration can best utilize the
 * alrealy computed values.</p>
 *
 * @param f the integrand function
 * @param min the lower bound for the interval
 * @param max the upper bound for the interval
 * @param n the stage of 1/2 refinement, n = 0 is no refinement
 * @return the value of n-th stage integral
 * @throws FunctionEvaluationException if an error occurs evaluating the
 * function
 */
double stage(final UnivariateRealFunction f,
             final double min, final double max, final int n)
    throws FunctionEvaluationException {

    if (n == 0) {
        s = 0.5 * (max - min) * (f.value(min) + f.value(max));
        return s;
    } else {
        final long np = 1L << (n-1);           // number of new points in this stage
        double sum = 0;
        final double spacing = (max - min) / np; // spacing between adjacent new points
        double x = min + 0.5 * spacing;    // the first new point
        for (long i = 0; i < np; i++) {
            sum += f.value(x);
            x += spacing;
        }
        // add the new sum to previously calculated result
        s = 0.5 * (s + sum * spacing);
        return s;
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:39,代码来源:TrapezoidIntegrator.java

示例6: stage

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
 * Compute the n-th stage integral.
 * @param f the integrand function
 * @param min the lower bound for the interval
 * @param max the upper bound for the interval
 * @param n number of steps
 * @return the value of n-th stage integral
 * @throws FunctionEvaluationException if an error occurs evaluating the
 * function
 */
private double stage(final UnivariateRealFunction f,
                     final double min, final double max, final int n)
    throws FunctionEvaluationException {

    // set up the step for the current stage
    final double step     = (max - min) / n;
    final double halfStep = step / 2.0;

    // integrate over all elementary steps
    double midPoint = min + halfStep;
    double sum = 0.0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < abscissas.length; ++j) {
            sum += weights[j] * f.value(midPoint + halfStep * abscissas[j]);
        }
        midPoint += step;
    }

    return halfStep * sum;

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:32,代码来源:LegendreGaussIntegrator.java

示例7: solve

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
 * Find a real root in the given interval with initial value.
 * <p>
 * Requires bracketing condition.</p>
 *
 * @param f function to solve (must be polynomial)
 * @param min the lower bound for the interval
 * @param max the upper bound for the interval
 * @param initial the start value to use
 * @return the point at which the function value is zero
 * @throws ConvergenceException if the maximum iteration count is exceeded
 * or the solver detects convergence problems otherwise
 * @throws FunctionEvaluationException if an error occurs evaluating the
 * function
 * @throws IllegalArgumentException if any parameters are invalid
 */
public double solve(final UnivariateRealFunction f,
                    final double min, final double max, final double initial)
    throws ConvergenceException, FunctionEvaluationException {

    // check for zeros before verifying bracketing
    if (f.value(min) == 0.0) {
        return min;
    }
    if (f.value(max) == 0.0) {
        return max;
    }
    if (f.value(initial) == 0.0) {
        return initial;
    }

    verifyBracketing(min, max, f);
    verifySequence(min, initial, max);
    if (isBracketing(min, initial, f)) {
        return solve(f, min, initial);
    } else {
        return solve(f, initial, max);
    }

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:41,代码来源:LaguerreSolver.java

示例8: testSinFunction

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
 * Test of interpolator for the sine function.
 * <p>
 * |sin^(n)(zeta)| <= 1.0, zeta in [0, 2*PI]
 */
public void testSinFunction() throws MathException {
    UnivariateRealFunction f = new SinFunction();
    UnivariateRealInterpolator interpolator = new NevilleInterpolator();
    double x[], y[], z, expected, result, tolerance;

    // 6 interpolating points on interval [0, 2*PI]
    int n = 6;
    double min = 0.0, max = 2 * Math.PI;
    x = new double[n];
    y = new double[n];
    for (int i = 0; i < n; i++) {
        x[i] = min + i * (max - min) / n;
        y[i] = f.value(x[i]);
    }
    double derivativebound = 1.0;
    UnivariateRealFunction p = interpolator.interpolate(x, y);

    z = Math.PI / 4; expected = f.value(z); result = p.value(z);
    tolerance = Math.abs(derivativebound * partialerror(x, z));
    assertEquals(expected, result, tolerance);

    z = Math.PI * 1.5; expected = f.value(z); result = p.value(z);
    tolerance = Math.abs(derivativebound * partialerror(x, z));
    assertEquals(expected, result, tolerance);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:NevilleInterpolatorTest.java

示例9: transformValue

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
protected double transformValue(double x, UnivariateRealFunction function) throws FunctionEvaluationException
{
	double tempY = scaleY;
	if(tempY == 0)//avoid division by zero.
		tempY = Double.MIN_VALUE;
	return (function.value((x-translateX)*scaleX)/scaleY+translateY);
}
 
开发者ID:sambayless,项目名称:golems,代码行数:8,代码来源:TransformationFunction.java

示例10: mapToSelf

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/** {@inheritDoc} */
public RealVector mapToSelf(UnivariateRealFunction function) throws FunctionEvaluationException {
    Iterator<Entry> it = (function.value(0) == 0) ? sparseIterator() : iterator();
    Entry e;
    while (it.hasNext() && (e = it.next()) != null) {
        e.setValue(function.value(e.getValue()));
    }
    return this;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:10,代码来源:AbstractRealVector.java

示例11: mapToSelf

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public ArrayRealVector mapToSelf(UnivariateRealFunction function) {
    for (int i = 0; i < data.length; i++) {
        data[i] = function.value(data[i]);
    }
    return this;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:9,代码来源:ArrayRealVector.java

示例12: findUpperBound

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
 * Find the upper bound b ensuring bracketing of a root between a and b
 * @param f function whose root must be bracketed
 * @param a lower bound of the interval
 * @param h initial step to try
 * @return b such that f(a) and f(b) have opposite signs
 * @exception FunctionEvaluationException if the function cannot be computed
 * @exception OptimizationException if no bracket can be found
 */
private double findUpperBound(final UnivariateRealFunction f,
                              final double a, final double h)
    throws FunctionEvaluationException, OptimizationException {
    final double yA = f.value(a);
    double yB = yA;
    for (double step = h; step < Double.MAX_VALUE; step *= Math.max(2, yA / yB)) {
        final double b = a + step;
        yB = f.value(b);
        if (yA * yB <= 0) {
            return b;
        }
    }
    throw new OptimizationException("unable to bracket optimum in line search");
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:24,代码来源:NonLinearConjugateGradientOptimizer.java

示例13: solve

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double solve(final UnivariateRealFunction f, double min, double max)
    throws MaxIterationsExceededException, FunctionEvaluationException {
        
    clearResult();
    verifyInterval(min,max);
    double m;
    double fm;
    double fmin;
    
    int i = 0;
    while (i < maximalIterationCount) {
        m = UnivariateRealSolverUtils.midpoint(min, max);
       fmin = f.value(min);
       fm = f.value(m);

        if (fm * fmin > 0.0) {
            // max and m bracket the root.
            min = m;
        } else {
            // min and m bracket the root.
            max = m;
        }

        if (Math.abs(max - min) <= absoluteAccuracy) {
            m = UnivariateRealSolverUtils.midpoint(min, max);
            setResult(m, i);
            return m;
        }
        ++i;
    }
    
    throw new MaxIterationsExceededException(maximalIterationCount);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:BisectionSolver.java

示例14: drawFunction

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
 * Draw the function, between (in the functions coordinates) minX, minY, and maxX and maxY. Draw it so that there is a point for every step'th pixel (so step is in screen coordinates).
 * @param g
 * @param function
 * @param minX
 * @param maxX
 * @param minY
 * @param maxY
 * @param step
 */
private void drawFunction(Graphics g, UnivariateRealFunction function, float minX, float maxX, float minY, float maxY, float step)
{		
	//use quad strips instead
	
	//
	
	float fStep;
	fStep = step* (maxX-minX)/(this.getAppearance().getContentWidth());
	
	int number =(int)( (maxX-minX)/fStep);
	if ((maxX-minX)%fStep>0)
		number ++;//there will be one extra end position
	number += 3;//the corners
	float[] xValues = new float[number];
	float[] yValues = new float[number];		
	
	xValues[0] = 0;
	yValues[0] = 0;
	float x = minX;
	try{		
	
		for (int i = 1; i<number-1;i++)
		{
			
			if (x> maxX)
				x = maxX;
			float y = (float)function.value(x);
			xValues[i] = getScaleX(x);
			yValues[i] = getScaleY(y);
			x+= fStep;
			//System.out.println(xValues[i] + "\t" + yValues[i] + "\t" +  this.getWidth()+ "\t" + this.getHeight());
		}
	
		xValues[number-1] = this.getAppearance().getContentWidth() ;
		yValues[number-1]=0;
	

	}catch(FunctionEvaluationException e)
	{
		
		StateManager.logError(e);
		return;
	}

	drawQuadStripFunction(g,xValues,yValues,getScaleX(minX), getScaleY(minY),Color.BLUE, Color.DARK_BLUE );
	
}
 
开发者ID:sambayless,项目名称:golems,代码行数:58,代码来源:GLFunctionPane.java

示例15: solve

import org.apache.commons.math.analysis.UnivariateRealFunction; //导入方法依赖的package包/类
/**
    * Find a zero in the given interval with an initial guess.
    * <p>Throws <code>IllegalArgumentException</code> if the values of the
    * function at the three points have the same sign (note that it is
    * allowed to have endpoints with the same sign if the initial point has
    * opposite sign function-wise).</p>
    *
    * @param f       function to solve.
    * @param min     the lower bound for the interval.
    * @param max     the upper bound for the interval.
    * @param initial the start value to use (must be set to min if no
    *                initial point is known).
    * @return the value where the function is zero
    * @throws MaxIterationsExceededException the maximum iteration count
    *                                        is exceeded
    * @throws FunctionEvaluationException    if an error occurs evaluating
    *                                        the function
    * @throws IllegalArgumentException       if initial is not between min and max
    *                                        (even if it <em>is</em> a root)
    */
   @Override
public double solve(final UnivariateRealFunction f,
                       final double min, final double max, final double initial)
           throws MaxIterationsExceededException, FunctionEvaluationException {

       clearResult();
       if ((initial < min) || (initial > max)) {
           throw MathRuntimeException.createIllegalArgumentException(
                   "invalid interval, initial value parameters:  lower={0}, initial={1}, upper={2}",
                   min, initial, max);
       }

       // return the initial guess if it is good enough
       double yInitial = f.value(initial);
       if (Math.abs(yInitial) <= functionValueAccuracy) {
           setResult(initial, 0);
           return result;
       }

       // return the first endpoint if it is good enough
       double yMin = f.value(min);
       if (Math.abs(yMin) <= functionValueAccuracy) {
           setResult(min, 0);
           return result;
       }

       // reduce interval if min and initial bracket the root
       if (yInitial * yMin < 0) {
           return solve(f, min, yMin, initial, yInitial, min, yMin);
       }

       // return the second endpoint if it is good enough
       double yMax = f.value(max);
       if (Math.abs(yMax) <= functionValueAccuracy) {
           setResult(max, 0);
           return result;
       }

       // reduce interval if initial and max bracket the root
       if (yInitial * yMax < 0) {
           return solve(f, initial, yInitial, max, yMax, initial, yInitial);
       }

       throw MathRuntimeException.createIllegalArgumentException(
               NON_BRACKETING_MESSAGE, min, max, yMin, yMax);

   }
 
开发者ID:CompEvol,项目名称:beast2,代码行数:68,代码来源:BrentSolver.java


注:本文中的org.apache.commons.math.analysis.UnivariateRealFunction.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。