Package jmathexpr.arithmetic.equation

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


    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

        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

        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

    }

    @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

    }

    @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

    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

        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

    }

    @Test(dependsOnMethods = { "parenthesis" })
    public void rationals() throws EquationSolveException {
//        Equation lineq = (Equation) new ExpressionParser().parse("3/4 x + 5/6 = 5x - 125/3");
        Equation lineq = (Equation) new ExpressionParser().parse("3/4*x + 5/6 = 5x - 125/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(Naturals.getInstance().create(10)));
    }
View Full Code Here

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

    @Test(dependsOnMethods = { "rationals" })
    public void fractions() throws EquationSolveException {
        Equation lineq = (Equation) new ExpressionParser().parse("(6x - 7)/4 + (3x - 5)/7 = (5x + 78)/28");
        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(3)));
    }
View Full Code Here

TOP

Related Classes of jmathexpr.arithmetic.equation.Equation

Copyright © 2018 www.massapicom. 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.