where x1 x2and x3are the roots of the cubic equation.
where:
discriminant(Δ) = q3 + r2
q = (3c - b2) / 9
r = -27d + b(9c - 2b2)
s = r + √ (discriminant)
t = r - √ (discriminant)
term1 = √ (3.0) * ((-t + s) / 2)
r13 = 2 * √ (q[/i])
and my code is:
#include <iostream.h>
#include <math.h>
main()
{
double a=1,b=-4,c=-9,d=36;
double q=(3*(c)-pow(b,2))/9; //finding q
float n=pow(b,2); //n=for use in r,square of b
double r=(-27*(d)+b*(9*(c)-2*n)); //finding r
float o=pow(q,3); //o=qube of q,for discriminant
float p=pow(r,2); //p=square of r,for discriminant
double discriminant=o+p;
double s = r + sqrt(discriminant);
double t = r - sqrt(discriminant);
double term1 = sqrt (3.0)*((-t+s)/2);
double r13 = 2*sqrt(q); the error occurs in below three lines:
double x1=(-term1+r13*cos(o/3));
double x2=(-term1+r13*cos(o+(2*3.145)/3));
double x3=(-term1+r13*cos(o+(4*3.145)/3));