Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- using namespace std;
- int main()
- {
- double pi = 3.1415926535897932384626;
- double a = -1;
- double b = 13;
- double c = -26;
- double d = 1;
- double p = (3.0*a*c - b*b)/3.0*a*a;
- double q = (2.0*b*b*b - 9.0*a*b*c + 27.0*a*a*d)/(27.0*a*a*a);
- cout << "p=" << p << endl;
- cout << "q=" << q << endl;
- double teta = acos((3.0*q)/(2.0*p) * sqrt(-3.0/p));
- double scale = 2.0*sqrt(-p/3.0);
- double off = -b/(3.*a);
- double x1 = off+scale*cos(teta/3.);
- double x2 = off+scale*cos(teta/3. - (2.0/3.0)*pi);
- double x3 = off+scale*cos(teta/3. - (4.0/3.0)*pi);
- cout << "X1=" << x1 << endl;
- cout << "X2=" << x2 << endl;
- cout << "X3=" << x3 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement