1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import random maxf = -1e9 print("Iter x y f(x,y)") for iter in range(10000+1): # x = [-2, 2] , y = [1, 3] true value : x = -1 , y = 1.5 x = -2 + 4 * random.random() y = 1 + 2 * random.random() # f(x) = y - x - 2x^2 - 2xy - y^2 fn = y - x -2*(x**2) - 2*x*y - y**2 if fn > maxf: maxf = fn maxx = x maxy = y if iter%1000 == 0: print("%5d %7.4f %7.4f %8.4f" % (iter, maxx, maxy, fn)) | cs |
'수학 > 수치해석' 카테고리의 다른 글
| [수치해석] Simple Fixed Point 파이썬 (0) | 2022.12.12 |
|---|---|
| [수치해석] Parabolic Interpolation 파이썬 (0) | 2022.12.10 |
| [수치해석] Golden Section Method 파이썬 (0) | 2022.12.09 |