diff options
Diffstat (limited to 'CSMath/src/bisection')
| -rw-r--r-- | CSMath/src/bisection/Bisection.java | 18 | ||||
| -rw-r--r-- | CSMath/src/bisection/PreBisection.java | 9 |
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;
|
