} while (!(current = current.getNextConsCell()).isNull());
}
private ArrayList<BigDec> stepSolveDomain() throws ParserException {
ArrayList<BigDec> solutions = new ArrayList<BigDec>();
BigDec accuracy = this.accuracy;
if ((answer.abs().gteq(new BigDec(10000000)) || answer.abs().lteq(new BigDec(0.00000001))) && answer.neq(BigDec.ZERO))
accuracy = answer.multiply(accuracy).abs();
int i = 0;
if (containsFactorial) {
delta = BigDec.ONE;
xMin = BigDec.ZERO;
xMax = new BigDec(50);
i = 6;
}
while ((solutions.size() == 0 && i < 4) || i == 6) {
int maxIterations = (int) Math.round(xMax.subtract(xMin).divide(delta).doubleValue());
for (int sign = 1; sign >= -1; sign -= 2) {
int iterationsSinceDirectionChange = 0;
delta = delta.multiply(new BigDec(sign));
BigDec slope = BigDec.ZERO, prevSlope = BigDec.ZERO;
BigDec point1[] = {xMin, getY(xMin)}, point2[] = {xMin.add(delta), getY(xMin.add(delta))};
slope = getSlope(point1, point2);
int prevDirection = getDirection(prevSlope, point1[1], sign), direction = getDirection(slope, point2[1], sign);
//Check if either of the starting points is a solution
if (point1[1].lteq(answer.add(accuracy)) && point1[1].gteq(answer.subtract(accuracy)))
solutions.add(new BigDec(point1[0]));
if (point2[1].lteq(answer.add(accuracy)) && point2[1].gteq(answer.subtract(accuracy)))
solutions.add(new BigDec(point2[0]));
if (solutions.size() > 0) //If the equation has solutions from the starting points, stop
return solutions;
while (iterationsSinceDirectionChange < maxIterations) {
if (direction != prevDirection && (prevDirection != 0 || (point1[0].eq(xMin) && !solutions.contains(xMin))) && (direction != 0 || (point2[0].eq(xMax) && !solutions.contains(xMax)))) {
BigDec possibleSolution = oscillator(point1, point2, slope, prevDirection, direction, sign, delta, accuracy);
if (possibleSolution != null) {
System.out.println("possibleSolution: (" + possibleSolution + ", " + getY(possibleSolution) + ")");
if (isAnswer(possibleSolution, accuracy))
solutions.add(possibleSolution);
}
}
else if (direction == 2) //Only need to check direction because all prevDirections except for the first one (which is checked elsewhere) were first stored in direction
solutions.add(point2[0]);
//Iteration
point1[0] = point2[0];
point1[1] = point2[1];
point2[0] = point2[0].add(delta);
point2[1] = getY(point2[0]);
prevSlope = new BigDec(slope);
slope = getSlope(point1, point2);
prevDirection = direction;
direction = getDirection(slope, point2[1], sign);
iterationsSinceDirectionChange++;
if (direction != prevDirection)
iterationsSinceDirectionChange = 0;
if ((containsFactorial && point2[0].multiply(new BigDec(sign)).gteq(xMax.multiply(new BigDec(sign)).add(xMin))) || solutions.size() >= 10 || point2[0].gt(domainMax.abs().multiply(new BigDec(3))))
break;
}
}
i++;
if (i < 4)
delta = delta.divide(new BigDec(2.0));
}
return solutions;
}