Advertisement
reeps

baluev_3.2

Mar 30th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 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. def f(x, y):
  13.     return g1(x, y) + g2(x, y)
  14. def g1(x, y):
  15.     return 6.5 * y
  16. def g2(x, y):
  17.     return -6.5 * y + math.exp(x + y)/(1 + math.sqrt(x)*y/2)
  18.  
  19. g1_int = 6.5 * (input_x_b - input_x_a) * (input_y_b / 2 - input_y_a / 2)
  20.  
  21. def single(f, x_limits, y_limits):
  22.     x_a, x_b = x_limits
  23.     y_a, y_b = y_limits
  24.     x = ROOT.gRandom.Uniform(x_a, x_b)
  25.     y = ROOT.gRandom.Uniform(y_a, y_b)
  26.     return (x_b - x_a) * (y_b - y_a) * f(x, y)
  27.  
  28. results = []
  29. for i in range(10):
  30.     cresults = []
  31.     for i in range(1000):
  32.         r = (single(g2, (0., 0.5), (1., 3.)))
  33.         results.append(r)
  34.         cresults.append(r)
  35.     average = sum(results) / len(results)
  36.     variance = (sum(r**2 for r in results) - average**2) / len(results)
  37.     caverage = sum(cresults) / len(cresults)
  38.     cvariance = (sum(r**2 for r in cresults) - caverage**2) / len(cresults)
  39.     print g1_int + caverage, math.sqrt(cvariance / len(cresults)),
  40.     print g1_int + average, math.sqrt(variance / len(results))
  41.  
  42. def f_for_drawing(x, p):
  43.     return g2(x[0], x[1])
  44.  
  45. tf2 = ROOT.TF2("f", f_for_drawing, 0., 0.5, 1., 3., 1)
  46. tf2.Draw("surf1z")
  47. sys.stdin.readline()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement