Advertisement
Checakus

Untitled

Mar 3rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1.  
  2.         public static int FoundN(AreaType areaType, double tolerantion)
  3.         {
  4.             int n = 1;
  5.             double integral = 0;
  6.  
  7.             while (n <= MAX_N)
  8.             {
  9.                 if (areaType == AreaType.Rectangle)
  10.                     integral = RectangleMethod(X1, X2, n);
  11.  
  12.                 if (areaType == AreaType.Trapezoid)
  13.                     integral = TrapezoidMethod(X1, X2, n);
  14.  
  15.                 double difference = Math.Abs(INTEGRAL_VALUE - integral);
  16.                 double differenceInPercent = (difference / Result.INTEGRAL_VALUE) * 100.0;
  17.                 if (differenceInPercent <= tolerantion)
  18.                 {
  19.                     break;
  20.                 }
  21.                
  22.                 n++;
  23.             }
  24.             return n;
  25.         }
  26.         private static double DegreeToRadian(double angle)
  27.         {
  28.             return Math.PI * angle / 180.0;
  29.         }
  30.  
  31.         private static double Function(double x)
  32.         {
  33.             return Math.Cos(DegreeToRadian(x));
  34.         }
  35.  
  36.  
  37. //button
  38. tolerantion = Convert.ToDouble(numericUpDown2.Value);
  39.  
  40.             textBox1.Text = Convert.ToString(Result.FoundN(AreaType.Rectangle, tolerantion));
  41.             textBox2.Text = Convert.ToString(Result.FoundN(AreaType.Trapezoid, tolerantion));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement