$y = x^2$


In [1]:
using PyPlot

In [2]:
x = 0:0.01:1
y = sqrt(1 - x.^2);

plot(x, y)
axis("image")


Out[2]:
(0.0,1.0,0.0,1.0)

In [3]:
using PyCall
@pyimport matplotlib.patches as patches
rectangle = patches.Rectangle


Out[3]:
PyObject <class 'matplotlib.patches.Rectangle'>

In [4]:
function draw_rectangle(x, y, xwidth, ywidth, color="grey")
    ax = gca()
    ax[:add_patch](rectangle((x, y), xwidth, ywidth, facecolor=color, alpha=0.5))
end


Out[4]:
draw_rectangle (generic function with 2 methods)

In [5]:
draw_rectangle(0.1, 0.1, 0.1, 0.1)
axis("image")


Out[5]:
(0.1,0.2,0.1,0.2)

In [6]:
step = 0.1
for i in 0.0:step:1.0
    for j in 0.0:step:1.0
        if i^2 + j^2 < 1.0
            color = "red"
        else
            color = "grey"
        end
        
        draw_rectangle(i, j, step, step, color)
    end
end
plot(x, y)
axis("image")


Out[6]:
(0.0,1.1,0.0,1.1)

In [ ]:
step = 0.01
for i in 0.0:step:1.0
    for j in 0.0:step:1.0
        if i^2 + j^2 < 1.0
            color = "red"
        else
            color = "grey"
        end
        
        draw_rectangle(i, j, step, step, color)
    end
end

plot(x, y)
axis("image")

In [1]:
step = 0.001
area = 0.0
for i in 0.0:step:1.0
    for j in 0.0:step:1.0
        
        if i^2 + j^2 < 1.0
            
            area += step^2
            
        end
    end
end

In [2]:
4*area


Out[2]:
3.1455200000071017

In [ ]: