From 8f42378c707c8c962082e394fe67ac3bb5cd557b Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 14 Oct 2018 11:42:53 -0400 Subject: General cleanup --- CSMath/src/bisection/Bisection.java | 18 ++++++++++++++++++ CSMath/src/bisection/PreBisection.java | 9 +++++++++ 2 files changed, 27 insertions(+) (limited to 'CSMath/src/bisection') 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; -- cgit v1.2.3