Examples of Polynomial


Examples of ca.eandb.jmist.math.Polynomial

    // now check for intersection of ray with the body
    Vector3    orig  = this.base.vectorTo(ray.origin());
    Vector3    dir    = ray.direction();

    Polynomial  f    = new Polynomial(
                orig.x() * orig.x() + orig.z() * orig.z() - this.radius * this.radius,
                2.0 * (orig.x() * dir.x() + orig.z() * dir.z()),
                dir.x() * dir.x() + dir.z() * dir.z()
              );
    double[]  x    = f.roots();

    if (x.length == 2)
    {
      // for each solution, make sure the point lies between the base and the apex
      p = ray.pointAt(x[0]);
View Full Code Here

Examples of ca.nengo.math.impl.Polynomial

  /*
   * Test method for 'ca.nengo.math.impl.LinearCurveFitter.fit()'
   */
  public void testFindCoefficients() {
    Function target = new Polynomial(new float[]{1f,4f,-3f,0.5f});
    CurveFitter lcf = new LinearCurveFitter();
    float[][] values = new float[2][10];
   
    for (int i=0; i<values[0].length; i++) {
      values[0][i] = -9 + i * 2;
      values[1][i] = target.map(new float[]{values[0][i]});
    }
   
    Function fitted = lcf.fit(values[0], values[1]);
   
//    Plotter.plot(target, -10, 0.1f, 10, "target");
//    Plotter.plot(fitted, -10, 0.5f, 10, "fitted");
   
    float targetVal = 0f;
    float fittedVal = 0f;
    for (int i=-8; i<9; i=i+2) {
      targetVal = target.map(new float[]{i});
      fittedVal = fitted.map(new float[]{i});
      TestUtil.assertClose(targetVal, fittedVal, 15f);
    }
 
  }
View Full Code Here

Examples of ca.nengo.math.impl.Polynomial

  /*
   * Test method for 'ca.nengo.math.impl.Polynomial.getDimension()'
   */
  public void testGetDimension() {
    Polynomial f = new Polynomial(new float[]{-1,0,1,2});
    assertEquals(1, f.getDimension());
  }
View Full Code Here

Examples of ca.nengo.math.impl.Polynomial

  /*
   * Test method for 'ca.nengo.math.impl.Polynomial.map(float[])'
   */
  public void testMap() {
    Polynomial f = new Polynomial(new float[]{-1,0,2,1});
    TestUtil.assertClose(2, f.map(new float[]{1}), .00001f);
    TestUtil.assertClose(15, f.map(new float[]{2}), .00001f);
    TestUtil.assertClose(-1, f.map(new float[]{-2}), .00001f);
    TestUtil.assertClose(-1, f.map(new float[]{0}), .00001f);
  }
View Full Code Here

Examples of ca.nengo.math.impl.Polynomial

  /*
   * Test method for 'ca.nengo.math.impl.Polynomial.multiMap(float[][])'
   */
  public void testMultiMap() {
    Polynomial f = new Polynomial(new float[]{-1,0,2,-1});

    float[] values = f.multiMap(new float[][]{new float[]{3}, new float[]{-2}});
    TestUtil.assertClose(-10, values[0], .00001f);
    TestUtil.assertClose(15, values[1], .00001f);
  }
View Full Code Here

Examples of ca.nengo.math.impl.Polynomial

    try {
      root = nrf.findRoot(func, -5, 15, 0.0001f);
    } catch (RuntimeException e) { // failure after too many attempts
    }
   
    func = new Polynomial(new float[]{4f, 2f, -3f, 1f});
    root = nrf.findRoot(func, -5, 15, 0.0001f);
    TestUtil.assertClose(func.map(new float[]{root}), 0, 0.001f);
   
    func = new SigmoidFunction(-1f, 0.3f, -0.5f, 1f);
    root = nrf.findRoot(func, -5, 5, 0.0001f);
View Full Code Here

Examples of jmathexpr.arithmetic.Polynomial

    public void testPolynomials() {
        Variable x = Numbers.variable("x");
//        Logger.dump(new ExpressionParser().parse("2x^2 - 5x"));
//        System.exit(1);
//        Polynomial a = Polynomial.create(new ExpressionParser().parse("x^3 - 2x^2 - 4"), x);
        Polynomial a = Polynomial.create(new ExpressionParser().parse("x^3 - 2*x^2 - 4"), x);
        Polynomial b = Polynomial.create(new ExpressionParser().parse("x - 3"), x);
        OrderedPair quotient = a.euclideanDivision(b);
       
        System.out.printf("(%s) : (%s) = %s%n", a, b, quotient);
       
        Polynomial q = Polynomial.create(new ExpressionParser().parse("x^2 + x + 3"), x);
        Polynomial r = Polynomial.create(N.create(5), x);
       
        assertEquals(quotient, new OrderedPair(q, r));
    }
View Full Code Here

Examples of jmathexpr.arithmetic.Polynomial

        List<Expression> terms = new ArrayList();
       
        terms.add(lhs);
        terms.add(new Negation(rhs));
       
        return new Polynomial(terms, x);
    }
View Full Code Here

Examples of jmathexpr.arithmetic.Polynomial

     *
     * @param x the indeterminate
     * @return a newly created polynomial instance
     */
    public Polynomial toPolynomial(Variable x) {
        return new Polynomial(terms, x);
    }
View Full Code Here

Examples of jmathexpr.arithmetic.Polynomial

            return true;
        }

        @Override
        public Expression apply() {
            Polynomial pl = Polynomial.create(((Equality) target).lhs(), x);
            Polynomial pr = Polynomial.create(((Equality) target).rhs(), x);
            Polynomial reduced;

            if (pl.degree().lt(pr.degree())) {
                reduced = pr.subtract(pl);
            } else {
                reduced = pl.subtract(pr);
            }
           
            Expression a = reduced.leadCoefficient();
           
            if (a instanceof ANumber && ((ANumber) a).isNegative()) {
                reduced = reduced.negate();
            }

            return new Equality(reduced, Naturals.zero());
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.