Examples of Equation


Examples of edu.cmu.relativelayout.equation.Equation

   * Returns a set containing all variables that have been added to this matrix.
   */
  private Set<Variable> getAllVariables() {
    Iterator<Equation> equationsList = this.equations.values().iterator();
    HashSet<Variable> variables = new HashSet<Variable>();
    Equation incorporating;

    while (equationsList.hasNext()) {
      incorporating = equationsList.next();
      variables.addAll(incorporating.getVariables());
    }
    return variables;
  }
View Full Code Here

Examples of edu.cmu.relativelayout.equation.Equation

    ret.solution = new double[numVariables][1];

    List<Variable> equationVariable;
    Variable variable;

    Equation incorporating;

    for (int i = 0; i < ret.body.length; i++) {
      if (this.equations.containsKey(allVariablesList.get(i))) {
        incorporating = this.equations.get(allVariablesList.get(i));
        equationVariable = incorporating.getVariables();
        ret.body[i][i] = 1;
        ret.solution[i][0] = incorporating.getRightHandSide();

        for (int j = 0; j < equationVariable.size(); j++) {
          variable = equationVariable.get(j);
          ret.body[i][allVariablesList.indexOf(variable)] = incorporating.getCoefficient(variable);
        }

      } else {
        ret.body[i][i] = 1;
      }
View Full Code Here

Examples of jmathexpr.arithmetic.equation.Equation

    @Override
    public void execute(Statement statement) {
        switch (statement.getCommand()) {
            case Solve:
                Equation eq = (Equation) statement.getExpression();
               
                try {
                    Set result = eq.solve();
                    Statement expression = new Statement(Command.Expression, result);
                   
                    ExpressionContext.getInstance().addStatement(expression);
                } catch (EquationSolveException e) {
                    System.err.println(e);
View Full Code Here

Examples of jmathexpr.arithmetic.equation.Equation

    public AbsoluteValueEquationTest() {
    }

    @Test
    public void linear() throws EquationSolveException {
        Equation abs = (Equation) new ExpressionParser().parse("|2x - 1| = 5");
        Variable x = abs.variable();
        System.out.printf("%s : %s = ?%n", abs, x);
       
        Set roots = abs.solve();
        System.out.printf("  %s = %s%n", x, roots);
       
        Expression expected = new FiniteSet(Naturals.getInstance().create(3), Integers.getInstance().create(-2));
        assertEquals(expected, roots);
    }
View Full Code Here

Examples of jmathexpr.arithmetic.equation.Equation

        assertEquals(expected, roots);
    }

    @Test(dependsOnMethods = { "linear" })
    public void toIsolate() throws EquationSolveException {
        Equation abs = (Equation) new ExpressionParser().parse("|5x - 6| + 3 = 10");
        Variable x = abs.variable();
        System.out.printf("%s : %s = ?%n", abs, x);
       
        Set roots = abs.solve();
        System.out.printf("  %s = %s%n", x, roots);
       
        Expression expected = new FiniteSet(Rationals.getInstance().create(13, 5), Rationals.getInstance().create(-1, 5));
        assertEquals(expected, roots);
    }
View Full Code Here

Examples of jmathexpr.arithmetic.equation.Equation

        assertEquals(expected, roots);
    }

    @Test(dependsOnMethods = { "toIsolate" })
    public void twoAbsExpressions() throws EquationSolveException {
        Equation abs = (Equation) new ExpressionParser().parse("|2x - 1| = |4x + 3|");
        Variable x = abs.variable();
        System.out.printf("%s : %s = ?%n", abs, x);
       
        Set roots = abs.solve();
        System.out.printf("  %s = %s%n", x, roots);
       
        Expression expected = new FiniteSet(Integers.getInstance().create(-2), Rationals.getInstance().create(-1, 3));
        assertEquals(expected, roots);
    }
View Full Code Here

Examples of jmathexpr.arithmetic.equation.Equation

    }

    @Test(dependsOnMethods = { "twoAbsExpressions" })
    public void quadratic() throws EquationSolveException {
        ExpressionParser parser = new ExpressionParser();
        Equation abs = (Equation) parser.parse("|x^2 - 6x + 1| = |(3x + 5)/2|");
        Variable x = abs.variable();
        System.out.printf("%s : %s = ?%n", abs, x);
       
        Set roots = abs.solve();
        System.out.printf("  %s = %s%n", x, roots);
       
        Expression x1 = parser.parse("(15 + sqrt(249)) / 4");
        Expression x2 = parser.parse("(15 - sqrt(249)) / 4");
        Expression expected = new FiniteSet(x1, x2, Rationals.getInstance().create(7, 2), Naturals.one());
View Full Code Here

Examples of jmathexpr.arithmetic.equation.Equation

    }

    @Test(dependsOnMethods = { "quadratic" })
    public void anotherQuadratic() throws EquationSolveException {
        ExpressionParser parser = new ExpressionParser();
        Equation abs = (Equation) parser.parse("|x| = x^2 + x - 3");
        Variable x = abs.variable();
        System.out.printf("%s : %s = ?%n", abs, x);
       
        Set roots = abs.solve();
        System.out.printf("  %s = %s%n", x, roots);
       
        Expression x1 = parser.parse("sqrt(3)");
        Expression x2 = Integers.getInstance().create("-3");
        Expression expected = new FiniteSet(x1, x2);
View Full Code Here

Examples of jmathexpr.arithmetic.equation.Equation

    public LinearEquationTest() {
    }

    @Test
    public void simple() throws EquationSolveException {
        Equation lineq = (Equation) new ExpressionParser().parse("4*x + 3 = x + 27");
        Variable x = lineq.variable();
        System.out.printf("%s : %s = ?%n", lineq, x);
       
        Set    roots = lineq.solve();
        System.out.printf("  %s = %s%n", x, roots);
       
        assertEquals(roots, new FiniteSet(Naturals.getInstance().create(8)));
    }
View Full Code Here

Examples of jmathexpr.arithmetic.equation.Equation

        assertEquals(roots, new FiniteSet(Naturals.getInstance().create(8)));
    }

    @Test(dependsOnMethods = { "simple" })
    public void parenthesis() throws EquationSolveException {
        Equation lineq = (Equation) new ExpressionParser().parse("2*(3*x - 7) + 4*(3*x + 2) = 6*(5*x + 9 ) + 3");
        Variable x = lineq.variable();
        System.out.printf("%s : %s = ?%n", lineq, x);
       
        Set    roots = lineq.solve();
        System.out.printf("  %s = %s%n", x, roots);
       
        assertEquals(roots, new FiniteSet(Rationals.getInstance().create(-21, 4)));
    }
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.