Advertisement
Xsufu

Монте-Карло

Dec 5th, 2020
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.49 KB | None | 0 0
  1. using System;
  2.  
  3. public class Test
  4. {
  5.     static double func(double x) {
  6.         return 1 / (Math.Pow(Math.Cosh(x),2));
  7.     }
  8.    
  9.     static void monte_carlo() {
  10.         double [] x = {2.7, 3.0, 3.3, 3.7, 4.0, 4.5, 4.9, 5.1};
  11.         double [] y = {0.3, -0.2, -0.7, -1.0, -0.9, -0.5, 0.2, 1.3};
  12.        
  13.         double in_d = 0.0 , out_d = 0.0;
  14.         for (int i = 0; i<8; i++){
  15.             if (y[i]<func(x[i])){
  16.                 in_d += 1;
  17.             }
  18.         }
  19.        
  20.         Console.WriteLine(in_d/8*3);
  21.     }
  22.    
  23.     public static void Main()
  24.     {
  25.         monte_carlo();
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement