public class Root
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static double |
bisection(Function f,
double x1,
double x2,
double tol)
Implements the bisection method for finding the root of a function.
|
static double[][] |
cubic(double a,
double b,
double c,
double d)
Solves for the roots of the cubic equation
ax3+bx2+cx+d=0.
|
static double[][] |
getJacobian(VectorFunction feqs,
int n,
double[] xx,
double tol)
Computes the Jacobian using a finite difference approximation.
|
static double |
newton(Function f,
double x,
double tol)
Implements Newton's method for finding the root of a function.
|
static double |
newton(Function f,
Function df,
double x,
double tol)
Implements Newton's method for finding the root of a function.
|
static double |
newtonBisection(Function f,
double xleft,
double xright,
double tol,
int icmax)
Implements Newton's method for finding the root but switches to the bisection method if the
the estimate is not between xleft and xright.
|
static double |
newtonMultivar(VectorFunction feqs,
double[] xx,
int max,
double tol) |
static double[][] |
quadratic(double a,
double b,
double c)
Solves for the complex roots of the quadratic equation
ax2+bx+c=0.
|
static double[] |
quadraticReal(double a,
double b,
double c)
Solves for the real roots of the quadratic equation
ax2+bx+c=0.
|
public static double[] quadraticReal(double a, double b, double c)
a
- double quadratic term coefficientb
- double linear term coefficientc
- double constant termpublic static double[][] quadratic(double a, double b, double c)
a
- double quadratic term coefficientb
- double linear term coefficientc
- double constant termpublic static double[][] cubic(double a, double b, double c, double d)
a
- double cubic term coefficientb
- double quadratic term coefficientc
- double linear term coefficientd
- double constant termpublic static double newton(Function f, double x, double tol)
f
- Function the functionx
- double guess the roottol
- double computation tolerancepublic static double newton(Function f, Function df, double x, double tol)
f
- Function the functiondf
- Function the derivative of the functionx
- double guess the roottol
- double computation tolerancepublic static double bisection(Function f, double x1, double x2, double tol)
f
- Function the functionx1
- double lowerx2
- double uppertol
- double computation tolerancepublic static double newtonBisection(Function f, double xleft, double xright, double tol, int icmax)
xleft
- doublexright
- doubletol
- double toleranceicmax
- int number of trialspublic static double newtonMultivar(VectorFunction feqs, double[] xx, int max, double tol)
public static double[][] getJacobian(VectorFunction feqs, int n, double[] xx, double tol)
feqs
- VectorFunction - the function containing n equationsn
- int - number of equationsxx
- double[] - the variable array at which the Jacobian is calculatedtol
- double - the small change to find the derivatives