Last active
March 27, 2017 14:31
-
-
Save c650/6003eaceb328dfcaaf492eb55d721feb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def f(x,y) | |
(((-0.0447 * x ** 6 + 0.2731 * x ** 5 - 0.7935 * x ** 4 + 1.7751 * x ** 3 - 2.561 * x ** 2 + 0.9885 * x + 1.0821) ** 2) - (y ** 2)) ** 0.5 | |
end | |
startx = 0 | |
endx = 2 | |
starty = -1.2 | |
endy = 1.2 | |
PIECES = 1000000.0 | |
xstep = (endx - startx) / PIECES | |
ystep = (endy - starty) / PIECES | |
area = xstep * ystep | |
sum = 0 | |
xx = startx | |
yy = starty | |
while xx < endx | |
while yy < endy | |
tmp = f(xx,yy) | |
sum += tmp unless tmp.is_a? Complex | |
yy += ystep | |
end | |
xx += xstep | |
end | |
puts area * sum * PIECES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Noticed the problem. The higher PIECES is, the smaller the resulting value. The way to fix it is to change line 32 to be
puts area * sum * PIECES
.