Go to the documentation of this file.
40#define CUBIC_ZERO 1.0e-100
43void cubic(
double a,
double b,
double c,
double d,
double *r1,
double *r2,
double *r3,
int *num)
56 double aa, p, q, D, u, v, phi;
61 if ( fabs(a) <=
norm ) {
62 if ( fabs(b) <=
norm ) {
63 if ( fabs(c) <=
norm ) {
64 if ( fabs(d) <=
norm ) {
78 if ( ( D = c * c - 4.0 * b * d ) < 0.0 ) {
84 if ( fabs(c) <
norm ) {
96 help = -( c +
sgn(c) * sqrt(D) ) / 2.0;
105 a = b / ( aa * 3.0 );
109 q = 2.0 * a * a * a - a * b + c;
110 D = q * q / 4.0 + p * p * p / 27.0;
118 * r2 =
cbrt(q / 2.0) - a;
119 * r1 = -2.0 * * r2 - a;
124 u = -q / 2.0 + sqrt(D);
131 p = sqrt(fabs(p) / 3.0);
132 help = ( -q / ( 2.0 * p * p * p ) );
133 if ( fabs(help) > 1.0 ) {
137 phi = acos(help) / 3.0;
138 double cp = cos(phi);
139 double sp = sqrt(3.0) * sin(phi);
140 * r1 = 2 * p * cp - a;
141 * r2 = -p * ( cp + sp ) - a;
142 * r3 = -p * ( cp - sp ) - a;
155void cubic3r(
double a,
double b,
double c,
double d,
double *r1,
double *r2,
double *r3,
int *num)
168 double aa, r, q, p, D, phi;
182 if ( ( D = c * c - 4.0 * b * d ) < 0.0 ) {
200 help = -( c +
sgn(c) * sqrt(D) ) / 2.0;
214 q = ( a * a - 3.0 * b ) / 9.0;
215 r = ( 2.0 * a * a * a - 9.0 * a * b + 27.0 * c ) / 54.0;
229 help = r / sqrt(q * q * q);
230 if ( fabs(help) > 1.0 ) {
237 * r1 = -2.0 *p *cos(phi / 3.0) - a / 3.0;
238 * r2 = -2.0 *p *cos( ( phi + 2.0 *
M_PI ) / 3.0 ) - a / 3.0;
239 * r2 = -2.0 *p *cos( ( phi + 2.0 *
M_PI ) / 3.0 ) - a / 3.0;
240 * r3 = -2.0 *p *cos( ( phi - 2.0 *
M_PI ) / 3.0 ) - a / 3.0;
268 return ( val + 1 > rank ? 1 : val + 1 );
278 double f1 = 0, f2 = 0, f3 = 0;
279 double sx = 0, sx2 = 0, sx3 = 0, sx4 = 0;
280 double detCi, Ci11, Ci12, Ci13, Ci22, Ci23, Ci33;
282 double yi, xi, xi2, xi3, xi4;
283 for (
int i = 0; i < n; ++i ) {
304 Ci11 = sx2 * sx4 - sx3 * sx3;
305 Ci12 = sx2 * sx3 - sx * sx4;
306 Ci13 = sx * sx3 - sx2 * sx2;
307 Ci22 = n * sx4 - sx2 * sx2;
308 Ci23 = sx * sx2 - n * sx3;
309 Ci33 = n * sx2 - sx * sx;
310 detCi = 1 / ( n * Ci11 + sx * Ci12 + sx2 * Ci13 );
311 a(0) = ( Ci11 * f1 + Ci12 * f2 + Ci13 * f3 ) * detCi;
312 a(1) = ( Ci12 * f1 + Ci22 * f2 + Ci23 * f3 ) * detCi;
313 a(2) = ( Ci13 * f1 + Ci23 * f2 + Ci33 * f3 ) * detCi;
314 }
else if ( n == 2 ) {
316 a(1) = ( y(1) - y(0) ) / ( x(1) - x(0) );
317 a(0) = y(0) - a(1) * x(0);
318 }
else if ( n == 1 ) {
330 }
else if ( i > 0 ) {
Index giveSize() const
Returns the size of receiver.
void zero()
Zeroes all coefficients of receiver.
double norm(const FloatArray &x)
double cbrt(double x)
Returns the cubic root of x.
void cubic3r(double a, double b, double c, double d, double *r1, double *r2, double *r3, int *num)
double signum(double i)
Returns the signum of given value (i = 0 returns 0, i < 0 returns -1, i > 0 returns 1).
void cubic(double a, double b, double c, double d, double *r1, double *r2, double *r3, int *num)
double sgn(double i)
Returns the signum of given value (if value is < 0 returns -1, otherwise returns 1).
int iperm(int val, int rank)
void ls2fit(const FloatArray &x, const FloatArray &y, FloatArray &a)
This page is part of the
OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak
Bořek Patzák
Project e-mail:
oofem@fsv.cvut.cz
Generated at for OOFEM by
doxygen
1.15.0 written by Dimitri van Heesch,
© 1997-2011