Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. double a, b, c, D, y1, y2, x1, x2, x3, x4; //We are solving bi-square equation of the kind ax^4+bx=0 , where a,b and c are coefficients
  6. //D is the discriminant.We replace x^2=y so we get an equation where y1 and y2 are radicals of the square equation
  7. //x1,x2,x3,x4 are radicals of the bi-square equation
  8. bool IsStarted = true;
  9. do
  10. {
  11.  
  12.  
  13.  
  14. cout << "a="; cin >> a;
  15.  
  16. cout << "b="; cin >> b;
  17.  
  18. cout << "c="; cin >> c;
  19.  
  20. //the acer input values of the coefficients
  21.  
  22.  
  23.  
  24. //if a=0 then we have incomplete quadratic equation
  25.  
  26. if (a == 0 ||b==0||c==04)
  27. {
  28. cout << "please,input value different from 0" << endl;
  29. continue;
  30. }
  31.  
  32. D = (b * b - 4 * a * c);
  33. cout << "D=" << D << endl;
  34. //depending on the discriminant we consider 3 cases
  35.  
  36.  
  37. if (D < 0)
  38. {
  39. cout << "the equation has no solution" << endl;
  40. //one of the cases is when the discriminant is lower than zero,then the equation doesnt have solution
  41. }
  42.  
  43. if (D == 0)
  44. {
  45. y1 = y2 = -b / (2 * a);
  46. cout << "y1=y2=" << y1 << endl;
  47. //in case when the discriminant is equal to zero we have only one dual radical
  48. }
  49.  
  50. if (D > 0)
  51. {
  52. y1 = -b / (2 * a) + sqrt(D) / (2 * a);
  53. y2 = -b / (2 * a) - sqrt(D) / (2 * a);
  54. cout << "y1=" << y1 << endl;
  55. cout << "y2=" << y2 << endl;
  56. //in case when the discriminant is bigger than zero,the square eguation has two radicals
  57.  
  58. if (y1 >= 0)
  59. {
  60. x1 = -sqrt(y1);
  61. x2 = sqrt(y1);
  62. cout << "x=" << x1 << endl;
  63. cout << "x=" << x2 << endl;
  64. //if the first radical if bigger ot equal to zero we can find the two radicals of the bi-square equation
  65. }
  66. else if (y1 < 0)
  67. {
  68. cout << " " << endl;
  69. //if the first radical ot the square equation is lower than zero then we dont have x1 and x2
  70. }
  71.  
  72. if (y2 >= 0)
  73. {
  74. x3 = -sqrt(y2);
  75. x4 = sqrt(y2);
  76. cout << "x=" << x3 << endl;
  77. cout << "x=" << x4 << endl;
  78. //if the seond radical of the square equation is bigger or equal to zero then we can find the other two radicals of the bi-square equation
  79. }
  80. else if (y2 < 0)
  81. {
  82. cout << " " << endl;
  83. //if the second radical of the square equation is lower than zero then we dont have x3 and x4
  84. }
  85.  
  86. }
  87.  
  88. IsStarted = false;
  89.  
  90. } while (IsStarted);
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement