00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _UT_RootFinder_h_
00021 #define _UT_RootFinder_h_
00022
00023 #include "UT_API.h"
00024
00025 #include <SYS/SYS_Types.h>
00026
00027 template<typename T> class UT_VectorT;
00028 typedef UT_VectorT<fpreal64> UT_Vector;
00029 class UT_Matrix;
00030 class UT_Complex;
00031 class UT_FloatArray;
00032 class UT_Vector2;
00033 class UT_Vector3;
00034
00035 class UT_API UT_RootFinder {
00036 public:
00037
00038
00039
00040
00041
00042
00043
00044
00045 static void laguerre(const UT_FloatArray &cf, UT_FloatArray &roots,
00046 int maxIters = 200);
00047
00048
00049
00050
00051
00052
00053 static int quadratic(fpreal32 a, fpreal32 b, fpreal32 c,
00054 fpreal32 &v0, fpreal32 &v1);
00055 static int quadratic(fpreal64 a, fpreal64 b, fpreal64 c,
00056 fpreal64 &v0, fpreal64 &v1);
00057
00058
00059
00060 static int quadratic(fpreal32 a, fpreal32 b, fpreal32 c,
00061 UT_Vector2 &r_roots, UT_Vector2 &i_roots);
00062
00063
00064
00065
00066
00067
00068 static int cubic(fpreal a, fpreal b, fpreal c, fpreal d,
00069 float &v0, float &v1, float &v2);
00070
00071
00072
00073
00074
00075
00076 static int cubic(fpreal a, fpreal b, fpreal c, fpreal d,
00077 UT_Vector3 &r_roots, UT_Vector3 &i_roots);
00078
00079
00080
00081
00082
00083 static int cubic(fpreal a, fpreal b, fpreal c, fpreal d,
00084 float x1, float x2, float r[3]);
00085
00086
00087
00088
00089
00090 static int quartic(fpreal a, fpreal b, fpreal c, fpreal d, fpreal e,
00091 float x1, float x2, float r[4]);
00092
00093
00094
00095 int brent(float (*func)(float x, void *data),
00096 void *data,
00097 fpreal x1, fpreal x2,
00098 fpreal tol, float &result, int maxIter=200);
00099
00100
00101 int newton(void (*func)(float x, float &val, float &der, void *data),
00102 void *data,
00103 float x1, float x2,
00104 float tol, float &result, int maxIter=200);
00105
00106
00107
00108
00109
00110 int newton(void (*func)(const UT_Vector &x, UT_Vector &val, UT_Matrix &jacobi, void *data),
00111 void *data,
00112 float tolx, float tolf,
00113 UT_Vector &result, int maxIter=200);
00114
00115
00116
00117 int newton(void (*func)(const UT_Vector &x, UT_Vector &val, UT_Matrix &jacobi, void *data),
00118 void *data,
00119 const UT_Vector &x1, const UT_Vector &x2,
00120 float tolx, float tolf,
00121 UT_Vector &result, int maxIter=200);
00122 };
00123
00124 #endif