reeps

baluev_3.1

Mar 30th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import sys, math, random, ROOT
  2.  
  3. input_x_a = 0.01
  4. input_x_b = 1
  5. input_y_a = 0
  6. input_y_b = 1
  7.  
  8. def f(x,y):
  9.     # return math.exp(x + y)/(1 + math.sqrt(x)*y/2)
  10.     return 1 / ( math.pow(x,2) * ( y + math.sin(x)/2 ) )
  11.  
  12.  
  13. def single(f, x_limits, y_limits):
  14.     x_a, x_b = x_limits
  15.     y_a, y_b = y_limits
  16.     x = ROOT.gRandom.Uniform(x_a, x_b)
  17.     y = ROOT.gRandom.Uniform(y_a, y_b)
  18.     return (x_b - x_a) * (y_b - y_a) * f(x, y)
  19.  
  20. results = []
  21. for i in range(10):
  22.     cresults = []
  23.     for i in range(1000):
  24.         r = (single(f, (input_x_a, input_x_b), (input_y_a, input_y_b)))
  25.         results.append(r)
  26.         cresults.append(r)
  27.     average = sum(results) / len(results)
  28.     variance = (sum(r**2 for r in results) - average**2) / len(results)
  29.     caverage = sum(cresults) / len(cresults)
  30.     cvariance = (sum(r**2 for r in cresults) - caverage**2) / len(cresults)
  31.     print caverage, math.sqrt(cvariance / len(cresults)),
  32.     print average, math.sqrt(variance / len(results))
  33.  
  34. def f_for_drawing(x, p):
  35.     return f(x[0], x[1])
  36.  
  37. tf2 = ROOT.TF2("f", f_for_drawing, input_x_a, input_x_b, input_y_a, input_y_b, 1)
  38. tf2.Draw("surf1z")
  39. sys.stdin.readline()
Add Comment
Please, Sign In to add comment