Advertisement
Guest User

Exercicio da Lista 2

a guest
Aug 29th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.   double pi = 3.1415926535897932384626;
  8.  
  9.   double a = -1;
  10.   double b = 13;
  11.   double c = -26;
  12.   double d = 1;
  13.  
  14.   double p = (3.0*a*c - b*b)/3.0*a*a;
  15.   double q = (2.0*b*b*b - 9.0*a*b*c + 27.0*a*a*d)/(27.0*a*a*a);
  16.  
  17.   cout << "p=" << p << endl;
  18.   cout << "q=" << q << endl;
  19.  
  20.   double teta = acos((3.0*q)/(2.0*p) * sqrt(-3.0/p));
  21.   double scale = 2.0*sqrt(-p/3.0);
  22.   double off = -b/(3.*a);
  23.  
  24.   double x1 = off+scale*cos(teta/3.);
  25.   double x2 = off+scale*cos(teta/3. - (2.0/3.0)*pi);
  26.   double x3 = off+scale*cos(teta/3. - (4.0/3.0)*pi);
  27.  
  28.   cout << "X1=" << x1 << endl;
  29.   cout << "X2=" << x2 << endl;
  30.   cout << "X3=" << x3 << endl;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement