Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A class containing a method to calculate a root of a given function.
- *
- * @author Daniel Augurell och Viktor R�dmark
- * @group Labbgrupp 4
- * @assignement Lab 3 part 2
- * @date 2011-09-27
- *
- */
- public class Secant {
- /**
- * Calculates a root of a given function between two given values.
- *
- * @param f The function
- * @param low The lower limit
- * @param high The higher limit
- * @param eps The accuracy of the calculation
- * @return The x value of the root
- */
- public static double secant(Function f, double low, double high, double eps) {
- double x = (high * f.f(low) - low * f.f(high)) / (f.f(low) - f.f(high));
- if (f.f(x + eps) * f.f(x - eps) > 0) {
- low = (f.f(x) < 0 ? x : low);
- high = (f.f(x) >= 0 ? x : high);
- x = secant(f, low, high, eps);
- }
- return x;
- }
- }
Add Comment
Please, Sign In to add comment