summaryrefslogtreecommitdiff
path: root/CSMath/src/bisection
diff options
context:
space:
mode:
authorbculkin2442 <bjculkin@mix.wvu.edu>2018-10-14 11:42:53 -0400
committerbculkin2442 <bjculkin@mix.wvu.edu>2018-10-14 11:42:53 -0400
commit8f42378c707c8c962082e394fe67ac3bb5cd557b (patch)
tree9b4070c764b8d0ed792d9f79a66fc169a237b949 /CSMath/src/bisection
parentf778a81e81506a4db455a6f506571c6bba935bf2 (diff)
General cleanup
Diffstat (limited to 'CSMath/src/bisection')
-rw-r--r--CSMath/src/bisection/Bisection.java18
-rw-r--r--CSMath/src/bisection/PreBisection.java9
2 files changed, 27 insertions, 0 deletions
diff --git a/CSMath/src/bisection/Bisection.java b/CSMath/src/bisection/Bisection.java
index edca743..324d127 100644
--- a/CSMath/src/bisection/Bisection.java
+++ b/CSMath/src/bisection/Bisection.java
@@ -8,12 +8,21 @@ package bisection;
* Use the bisection method to find bracketed roots of arbitrary real-valued functions.
*/
+/**
+ * Bisect a curve to find bracketed roots of arbitrary real-valued functions.
+ * @author bjculkin
+ *
+ */
public class Bisection {
/**
* Maximum number of iterations to attempt.
*/
public static final int MAXITR = 500;
+ /**
+ * Main method.
+ * @param args Unused CLI args.
+ */
public static void main(String[] args) {
/* The variable to manipulate in the expressions. */
Dual varX = new Dual();
@@ -115,6 +124,15 @@ public class Bisection {
return newmid;
}
+ /**
+ * Bisect an arbitrary expression using the secant method.
+ * @param func The expression to bisect.
+ * @param var The variable to manipulate.
+ * @param lo The lower bounding value.
+ * @param hi The higher bounding value.
+ * @param tol The tolerance to find the answer to.
+ * @return The bisected root for the expression, within the specified tolerance.
+ */
public static double secant(DualExpr func, Dual var, double lo, double hi, double tol) {
/* Initial guesses for root. */
double guess1 = (lo + hi) / 3; // 1/3 into the range
diff --git a/CSMath/src/bisection/PreBisection.java b/CSMath/src/bisection/PreBisection.java
index 39bbd60..ef56610 100644
--- a/CSMath/src/bisection/PreBisection.java
+++ b/CSMath/src/bisection/PreBisection.java
@@ -9,7 +9,16 @@ package bisection;
*/
import java.util.function.DoubleUnaryOperator;
+/**
+ * Previous attempt at bisection.
+ * @author bjculkin
+ *
+ */
public class PreBisection {
+ /**
+ * Main method.
+ * @param args Unused CLI args.
+ */
public static void main(String[] args) {
// The functions we're approximating a root for
DoubleUnaryOperator functionA = x -> Math.cos(x) - x;