Skip to content

Commit 00868e8

Browse files
committed
integration, root finding, quadratic equations and tartaglia's roots work once again.
1 parent 524ef06 commit 00868e8

11 files changed

Lines changed: 521 additions & 635 deletions

File tree

‎src/main/java/com/github/gbenroscience/math/numericalmethods/NumericalIntegral.java‎

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public double findHighRangeIntegralWithAdvancedPolynomial() {
507507
public double findHighRangeIntegral() {
508508
double dx = 0.2;
509509
NumericalIntegral integral = new NumericalIntegral();
510-
510+
511511
try {
512512
if (Math.abs(xUpper - xLower) < dx) {
513513
return findGaussianQuadrature();
@@ -548,10 +548,10 @@ public double findHighRangeIntegral() {
548548
} else if (xUpper < xLower) {
549549
double x = xLower;
550550
for (; x > (xUpper + dx); x -= dx) {
551-
integral.xLower = x;
552-
integral.xUpper = x-dx;
553-
integral.iterations = iterations;
554-
integral.function = function;
551+
integral.xLower = x;
552+
integral.xUpper = x - dx;
553+
integral.iterations = iterations;
554+
integral.function = function;
555555
sum += integral.findGaussianQuadrature();
556556
}//end for
557557

@@ -641,13 +641,14 @@ public double findAdvancedPolynomialIntegral() {
641641
*
642642
*/
643643
public static void extractFunctionStringFromExpression(List<String> list) {
644-
//[intg,(,F,1,2]
644+
//[intg, (, F, ,, 2, ,, 3, )]
645645

646646
if (list.get(0).equals("quad")) {
647647
list.set(0, "intg");
648648
}
649+
String methodName = list.get(0);
649650
String args1, args2, args3;
650-
if (list.get(0).equals("intg") && list.get(1).equals("(") && list.get(list.size() - 1).equals(")")) {
651+
if (methodName.equals("intg") && list.get(1).equals("(") && list.get(list.size() - 1).equals(")")) {
651652
String functionName = list.get(2);
652653
if (Variable.isVariableString(functionName)) {
653654
boolean exists = FunctionManager.contains(functionName);
@@ -666,14 +667,36 @@ public static void extractFunctionStringFromExpression(List<String> list) {
666667
}
667668
}
668669
}
669-
args1 = list.get(3);
670-
args2 = list.get(4);
671-
args3 = list.get(5);
672-
if (Number.validNumber(args1) && Number.validNumber(args2)) {
673-
if (!Number.validNumber(args3) && !Operator.isClosingBracket(args3)) {
674-
list.clear();
670+
//[intg,(,F,|,n1,|,n2,|,i,),]
671+
int sz = list.size();
672+
args1 = sz >= 8 ? list.get(4) : null;//compulsory---xLower
673+
args2 = sz >= 8 ? list.get(6) : null;//compulsory---xUpper
674+
args3 = sz >= 10 ? list.get(8) : null;//optional---iterations
675+
676+
if (Number.isNumber(args1) && Number.isNumber(args2)) {//found 2 number args
677+
if(Number.isNumber(args3)){//3rd number arg exists
678+
if(Operator.isClosingBracket(list.get(9))){//ensure that the next token is a close bracket
679+
//valid
680+
}else{
681+
System.err.println("The next token must be a close bracket after the 3 number arguments supplied to the `"+methodName+"` method");
682+
list.clear();
683+
}
684+
}else if(args3 == null){//2 number args only---still fair
685+
if(Operator.isClosingBracket(list.get(7))){//enforce that the next token is a close bracket
686+
//valid
687+
}else{
688+
System.err.println("The next token must be a close bracket after the 2 number arguments supplied to the `"+methodName+"` method");
689+
list.clear();
690+
}
675691
}
692+
else{
693+
list.clear();
694+
}
695+
} else {
696+
System.err.println("The `"+methodName+"` method needs at least 2 number args after the function handle: `"+functionName+"`");
697+
list.clear();
676698
}
699+
677700
}
678701
}//end method
679702

0 commit comments

Comments
 (0)