Advertisement
czlowiekzgon

Untitled

May 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace lab5
  8. {
  9. abstract class Zalozenia
  10. {
  11. Zalozenia(double e){
  12. error = e;
  13. }
  14. ~Zalozenia() {
  15.  
  16. }
  17. protected double error;
  18. virtual public double sqrtNumber(double num){
  19. double temp = 0, temp2 = 0;
  20. if (this.error == 0)
  21. {
  22. if (num >= 0)
  23. {
  24. temp = Math.Sqrt(num);
  25. }
  26. else
  27. {
  28. temp = Math.Sqrt(-(num));
  29. }
  30. }
  31. else if (this.error > 0 && this.error <= 0.1)
  32. {
  33. if (num >= 0)
  34. {
  35. temp = 1.0 * (num / 2);
  36. temp2 = 1.0 * (num / temp);
  37. }
  38. else
  39. {
  40. temp = 1.0 * (-(num) / 2);
  41. temp2 = 1.0 * (-(num) / temp);
  42. }
  43.  
  44. for (; ; )
  45. {
  46. if (Math.Abs(temp - temp2) < this.error || Math.Pow(temp, 2) == num)
  47. {
  48. break;
  49. }
  50. else
  51. {
  52. temp = (1.0 * temp + temp2) / 2;
  53. temp2 = (1.0 * num) / (1.0 * temp);
  54. }
  55. }
  56.  
  57. }
  58. else if (this.error > 0.1)
  59. {
  60. if (num >= 0)
  61. {
  62. temp = 1.0 * (num / 2);
  63. temp2 = 1.0 * (num / temp);
  64. }
  65. else
  66. {
  67. temp = 1.0 * (-(num) / 2);
  68. temp2 = 1.0 * (-(num) / temp);
  69. }
  70.  
  71. for (; ; )
  72. {
  73. if (Math.Abs(temp - temp2) < this.error || Math.Pow(temp, 2) == num)
  74. {
  75. break;
  76. }
  77. else
  78. {
  79. temp2 = temp;
  80. temp = temp2 - ((Math.Pow(temp2, 2) - num) / (2 * temp2));
  81. }
  82. }
  83. }
  84. return temp;
  85.  
  86. }
  87. virtual public void wyswietl()
  88. {
  89.  
  90. }
  91. virtual public void rozwiazRownanie()
  92. {
  93.  
  94. }
  95.  
  96.  
  97.  
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement