37.2 怎么解一元三次方程?
用“盛金公式”求解:
----------------------------------------------main.cpp ------------------------------------------
main.cpp
float* roots_cubic_equation(float a, float b, float c, float d) {
//the first element is the number of the real roots, and other elements are the real roots.
//Shengjin's formula
float *roots = new float[4];
if (a == 0) {
roots = roots_quadratic_equation(b, c, d);
}
else {
float A = b*b - 3*a*c;
float B = b*c - 9*a*d;
float C = c*c - 3*b*d;
float deita = B*B - 4*A*C;
if ((A == B) && (A == 0)) {
//the three roots are the same
if (a != 0) {
roots[1] = -b/(3*a);
}
else {
if (b != 0) {