reeps

baluev_3.1-3

Mar 30th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 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 1 / ( math.pow(x,2) * ( y + math.sin(x)/2 ) ) - 1/(math.pow(x,2) + y)
  10.     return 1 / ( math.pow(x,2) * ( y + math.sin(x)/2 ) ) - 1/(math.pow(x,2) + y) + 1/( math.pow(x,2) * ( y + 0.01/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. outerN = 10
  21. innerN = 1000
  22.  
  23. sumtot = 0
  24. sum2tot = 0
  25. ntot = 0
  26.  
  27. for i in range(outerN):
  28.     sumloc, sum2loc, nloc = [0,0,0]
  29.     for j in range(innerN):
  30.         r = (single(f, (input_x_a, input_x_b), (input_y_a, input_y_b)))
  31.         sumloc += r
  32.         sum2loc += r**2
  33.  
  34.     sumtot += sumloc
  35.     sum2tot += sum2loc
  36.     ntot += 1000
  37.  
  38.     run_average = 525.027 + sumloc / innerN
  39.     run_variance = (sum2loc / innerN) - (run_average)**2
  40.     run_sigma = math.sqrt( run_variance / innerN )
  41.  
  42.     average = 525.027 + sumtot / ntot
  43.     variance = (sum2tot / ntot) - (sumtot / ntot)**2
  44.     sigma = math.sqrt( variance / ntot )
  45.  
  46.     print run_average, " +/- ", run_sigma,
  47.     print average, " +/- ", sigma
  48.  
  49. def f_for_drawing(x, p):
  50.     return f(x[0], x[1])
  51.  
  52. tf2 = ROOT.TF2("f", f_for_drawing, input_x_a, input_x_b, input_y_a, input_y_b, 1)
  53. tf2.Draw("surf1z")
  54. sys.stdin.readline()
Advertisement
Add Comment
Please, Sign In to add comment