# How to Make Table with Computation Result in Julia (Using DataFrames Package or similar ones)

**URL:** <https://discourse.julialang.org/t/how-to-make-table-with-computation-result-in-julia-using-dataframes-package-or-similar-ones/91808>\
**Category:** General Usage\
**Tags:** package\
**Created:** [December 18, 2022, 11:20am UTC](https://discourse.julialang.org/t/how-to-make-table-with-computation-result-in-julia-using-dataframes-package-or-similar-ones/91808 "2022-12-18T11:20:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [December 18, 2022, 11:20am UTC](https://discourse.julialang.org/t/how-to-make-table-with-computation-result-in-julia-using-dataframes-package-or-similar-ones/91808/1 "2022-12-18T11:20:22Z")

</div>

Hi all,

I have recently modify the code to calculate all methods to approximate definite integral, my question is how to create a table with the resulting computation for different partitions (4, 8, 16).

This is the code with the function:

```julia
f(x) = sin(x^2)
a, b = 0, 2

function riemann(f::Function, a::Real, b::Real, n::Int; method="right")
    if method == "right"
        meth = f -> (lr -> begin l,r = lr; f(r) * (r-l) end)
	xs = range(a, b, n+1)
        pairs = zip(xs[begin:end-1], xs[begin+1:end]) # (x₀,x₁), …, (xₙ₋₁,xₙ)
        sum(meth(f), pairs)
    elseif method == "left"
        meth = f -> (lr -> begin l,r = lr; f(l) * (r-l) end)
	xs = range(a, b, n+1)
        pairs = zip(xs[begin:end-1], xs[begin+1:end]) # (x₀,x₁), …, (xₙ₋₁,xₙ)
        sum(meth(f), pairs)
    elseif method == "trapezoid"
        meth = f -> (lr -> begin l,r = lr; (1/2) * (f(l) + f(r)) * (r-l) end)
	xs = range(a, b, n+1)
        pairs = zip(xs[begin:end-1], xs[begin+1:end]) # (x₀,x₁), …, (xₙ₋₁,xₙ)
        sum(meth(f), pairs)
    elseif method == "simpsons"
        meth = f -> (lr -> begin l,r = lr; (1/6) * (f(l) + 4*(f((l+r)/2)) + f(r)) * (r-l) end)
	xs = range(a, b, n+1)
        pairs = zip(xs[begin:end-1], xs[begin+1:end]) # (x₀,x₁), …, (xₙ₋₁,xₙ)
        sum(meth(f), pairs)
    elseif method == "midpoint"
	xs = a:(b-a)/n:b
        deltas = diff(xs) # forms x2-x1, x3-x2, ..., xn-xn-1
        cs = [(xs[i] + xs[i+1])/2 for i in 1:length(deltas)]
        sum(f(cs[i]) * deltas[i] for i in 1:length(deltas))
    end
end

```

to test the result you can type at REPL:

```julia
riemann(f, 0, 2, 8, method="left")
riemann(f, 0, 2, 8, method="right")
riemann(f, 0, 2, 8, method="midpoint")
riemann(f, 0, 2, 8, method="trapezoid")
riemann(f, 0, 2, 8, method="simpsons")

```

then I have this code to create truth tables that might be able to help construct the table,

```julia
# ⊻ = xor (exclusive or)
# ⊼ = nand (not and)
# ⊽ = nor (not or)

using DataFrames, PrettyTables
df=DataFrame(p=repeat([true, false],inner=4), q=repeat([true, false],inner=2,outer=2), r=repeat([true, false],outer=4))

df[!,"~p"].=.!(df.p)
#df[!,"~q"].=.!(df.q)
#df[!,"~r"].=.!(df.r)
#df[!,"p ⩓ q"].=df.p.&&df.q
#df[!,"p ⩔ q"].=df.p.||df.q
#df[!,"p ⊻ q"] .=df.p .⊻ df.q
#df[!,"p ⊼ q"] .=df.p .⊼ df.q
#df[!,"p ⊽ q"] .=df.p .⊽ df.q
df[!,"~(p ⩓ ~p"].=.!(df.p.&&.!(df.p))
df[!,"p ⩔ ~p"].=df.p.||.!(df.p)
df[!,"p ⩔ q ⩔ r ⩔ ~(r ⩓ q)"].= (df.p.||df.q.||df.r) .|| .!(df.r .&& df.q)

pretty_table(df, nosubheader=true)

```

I want to achieve like this image below:  
 ![Capture d’écran_2022-12-18_18-12-35](https://global.discourse-cdn.com/julialang/original/3X/2/7/279f6c702975ba59485e8975d89abf0a6a3429ba.png)

The calculation of all methods to calculate the definite integrals with 4, 8 and 16 partitions.
