# Horizontal Slicing in Integral

Hi all,

it is quite hard for me to understand for part (c)

this is the question: I have worked on part (b):

Basically just make integral from the interval [1,c] and find half the area of part (a)

\int_{1}^{c} \frac{1}{x^{2}} = \frac{5}{12}

I get the c=12/7

using Plots, LaTeXStrings, SymPy
gr()

x = collect(range(0, 4, length= 100))
f(x) = 1/(x^2)

function Area(f, a, b, n)
xs = a:(b-a)/n:b
deltas = diff(xs)
cs = xs[1:end-1]
sum(f(cs[i]) * deltas[i] for i in 1:length(deltas))
end

r1 = round(Area(x -> 1/(x^2), 1, 12/7, 50000), digits=5)
r2 = round(Area(x -> 1/(x^2), 12/7, 6, 50000), digits=5)

plot(f,0,7, xtick=1:5:6, xlims=(0,7), ylims=(0,1.2),
framestyle=:zerolines,
label=L"f(x) = \frac{1}{x^{2}}", legend=:topright)

# Fill the area
plot!(f,1,12/7, label="", fill=(0, 0.25, :blue))
plot!(f,12/7,6, label="", fill=(0, 0.45, :blue))

# The line that bisects the area vertically
plot!([12/7], seriestype="vline", color=:green, label="")

# Annotate the x line that bisects the area
annotate!([(12/7,-0.05, (L"x = \frac{12}{7}", 7, :blue))])

# Annotate the area
annotate!([(1.33,0.25, ("Left area =", 7, :black))])
annotate!([(1.3,0.15, (r1, 7, :black))])
annotate!([(2.23,0.05, ("Right area = ", 7, :black))])
annotate!([(2.97,0.05, (r2, 7, :black))])



then I try to work on part (c), the horizontal slicing, but the result is questionable, I still don’t understand

If I do this x = \frac{1}{\sqrt{y}}, and the interval will be [1/36,1], then the integral should be:

\int_{d}^{1} \frac{1}{\sqrt{y}} = \frac{5}{12}

I will get d=0.627, but when I calculate the integral for the area of this function in y terms: it get the area of 20/12 \approx 1.66667

But the integral for area of this function in x terms get the total area of half the area in y terms: it get the area of 10/12 \approx 0.8333

Which part is it that I am missing or lost?

I think you have an extra part: The strip 0 < x < 1 && 1/36 < y < 1 is not part of the area when calculating using y = 1/x^2, while it is when integrating x = 1/sqrt(y).

So you might want to integrate x = 1/sqrt(y) - 1.

In the other direction, when calculating the area, the strip 1 < x < 6 && 0 < y < 1/36 is included and you need to decide if this is part of the area or not. If it is, and is not in the other direction, then you need to adjust what ‘half the area’ means in each direction (specifically, 5/12 isn’t the same in the other direction).

Hope this clears up the source of the inconsistency.

Well, I read the manual / solution, and still confused since I do not get half the area after integrating \int_{d}^{1} \frac{1}{\sqrt(y)}

it becomes \frac{5}{12} \approx 0.4163 with d=0.627

and then

\int_{1/36}^{d} \frac{1}{\sqrt(y)}

becomes 1.25033329825300

The solution might have a mistake!
They add (1/36)*5 at the top of the answer, corresponding to the horizontal strip below 1/36, but they forget to subtract (1 * (35/36)) which is the extra vertical strip calculated by the integral.

I think so too, the solution is a mistake and add more confusion for me.

I plot part (c) like this: With part (b) everything seems so smooth and easy to understand:

Trying to fix the answer, we have

integral(1/sqrt(y) from d to 1) = 5/12 + 1*(1-d)
# last term the added area


so

2*sqrt(y) from d to 1 = 17/12 - d
d - 2*sqrt(d) + 7/12 = 0


The solution of which is:

# ignoring 2nd solution outside range
1-sqrt(5/12) ~ 0.3545
# but 0.3545 is sqrt(d) so
d ~ 0.3545^2 ~ 0.1257


So try using the line y = 0.1257 to bisect.

Also, in the flipped chart, it would be better to color the region only between x = 1 and x = 6 to get the area right. The x = 6 doesn’t need any change, but the x = 1 requires to color from a little above the axis. Finally, you might want to color the rectangle 1 < x < 6 && 0 < y < 1/36 in the flipped chart.

1 Like

I try to solve the quadratic using Sympy:

d = symbols("d")

p = d-2*sqrt(d) + 7/12

solve(p,d)


2-element Vector{Sym}:
** 0.125672217930861**
** 2.70766111540247**

Thus when I plot at the original function:

It looks convincing.

But I want to know why do you add  1*(1-d) ? in

integral(1/sqrt(y) from d to 1) = 5/12 + 1*(1-d)


the reasonable why you add that term? Because I want to logically understand this solution.

(numerical error in prev answer fixed)

As for 1*(1-d) this is the area of the strip 0 < x < 1 and d < y < 1 which gets added in the integral (because it calculates area from axis and not from 1 and the integral length is 1-d).

In the chart, you can now add the Top area and Bottom area annotations.

Alright, after a long thinking. This is what I thought would be right:

for the flipped chart \frac{1}{\sqrt{y}}

my justification is:

\int_{0.340472}^{0.627} \frac{1}{\sqrt{y}} \ dy= \int_{0.627}^{1} \frac{1}{\sqrt{y}} \ dy \approx 0.41633

thus it will make the sum as half the area of part (a).

The code for the flipped chart:

using Plots, LaTeXStrings, Plots.PlotMeasures, SymPy
gr()

f(x) = 1/(sqrt(x))

function Area(f, a, b, n)
xs = a:(b-a)/n:b
deltas = diff(xs)
cs = xs[1:end-1]
sum(f(cs[i]) * deltas[i] for i in 1:length(deltas))
end

r1 = round(Area(x -> 1/(sqrt(x)), 0.340472, 0.627, 50000), digits=5)
r2 = round(Area(x -> 1/(sqrt(x)), 0.627, 1, 50000), digits=5)

plot(f,0,2, xtick=false, xlims=(0,1.2), ylims=(0,6.2),
framestyle=:zerolines, bottom_margin=5mm,
label=L"x = \frac{1}{\sqrt{y}}", legend=:topright)

# Fill the area
plot!(f,0.340472,0.627, label="", fill=(0, 0.25, :blue))
plot!(f,0.627,1, label="", fill=(0, 0.45, :blue))

# The line that bisects the area vertically
plot!([0.627], seriestype="vline", color=:green, label="")

# Annotate the interval tick line
annotate!([(0.340472,-0.01, (L"|", 6, :blue))])
annotate!([(0.340472,-0.27, (L"y = 0.34047", 6, :blue))])
annotate!([(0.63,-0.01, (L"|", 6, :blue))])
annotate!([(0.627,-0.27, (L"y = 0.627", 6, :blue))])
annotate!([(1,-0.01, (L"|", 6, :blue))])
annotate!([(1,-0.27, (L"y = 1", 6, :blue))])

# Annotate the area
annotate!([(0.42,1.15, ("Left area =", 6, :black))])
annotate!([(0.55,1.15, (r1, 6, :black))])
annotate!([(0.73,0.55, ("Right area = ", 6, :black))])
annotate!([(0.83,0.55, (r2, 6, :black))])



You can use SymPy a bit more easily here by integrating from d to 1/1^2 (the top half), so there is no need to adjust for the bottom rectangle, as the median is above 1/6^2:

julia> a, b = 1, 6
A =(1, 6)

julia> @syms x
(x,)

julia> A = integrate(1/x^2, (x, a, b))
5/6

julia> @syms c
(c,)

julia> solve(integrate(1/x^2, (x, a, c)) ~ A/2, c)
1-element Vector{Sym}:
12/7

julia> @syms d
(d,)

julia> # y = 1/x^2 -> x = 1/sqrt(y)

julia> @syms y
(y,)

julia> solve(integrate(1/sqrt(y), (y, d, 1)) ~ A/2)
1-element Vector{Sym}:
361/576

1 Like

Thanks a lot @j_verzani

how a newbie will know that d is above 1/36 (1/6^2) ? is it intuition?