public Vector substitution(Matrix matrix, Vector b, SubstitutionDirection direction) throws ArithmeticException
    {
        Double term0 = 0d;
        Double term1 = 0d;
        Double term2 = 0d;
        Vector y = new Vector();
        
        if (direction == SubstitutionDirection.FORWARD)
        {
            y.set(0, b.get(0));
            
            for (int row = 1; row < 2; row++)
            {
                term0 = term0 + matrix.values[row][0] * y.get(0);
                
                term1 = b.get(row) - term0;
                term2 = term1 / matrix.values[row][row];
                
                y.set(row, term2);
            }
        }
        
        if (direction == SubstitutionDirection.BACKWARD)
        {
            int dim = 1;
            
            y.set(dim, b.get(dim) / matrix.values[dim][dim]);
            
            for (int row = dim; row >= 0; row--)
            {
                term0 = 0d;
                for (int i = 0; i < dim - row; i++)
                {
                    term0 = term0 + matrix.values[row][dim - i] * y.get(dim - i);
                }
                term1 = b.get(row) - term0;
                term2 = term1 / matrix.values[row][row];
                y.set(row, term2);
            }
        }
        
        return y;
    }