Hi all,
I want to show the result of my computation in pi terms, instead of float with lots of decimal numbers. Is it possible?
Here is my code:
using Plots, LaTeXStrings; gr()
#=
# To plot a curve starting at (0, 0)
θ = 0:0.1:4.1π
x = θ .- sin.(θ)
y = 1 .- cos.(θ)
plot(x, y, xlims=(0,15), ylims=(0,4),
label=L"(x,y) = (\theta - \sin \ t , 1 - \cos \ t)",
framestyle=:zerolines, aspect_ratio=:equal)
=#
println("t \t x \t \t y")
for N in 0:pi/2:4*pi
x1 = (N) - sin.(N)
y1 = 1 - cos.(N)
println("$N \t $x1 \t $y1")
end
I want it like the left table:
Dan
2
Here is an idea using PrettyTables package:
julia> using PrettyTables
julia> println(pretty_table(String,
vcat([[string(t)*"π" t*π-sinpi(t) 1-cospi(t)] for t in 0:0.5:4]...);
header=["t", "x(t)", "y(t)"]))
┌──────┬──────────┬──────┐
│ t │ x(t) │ y(t) │
├──────┼──────────┼──────┤
│ 0.0π │ 0.0 │ 0.0 │
│ 0.5π │ 0.570796 │ 1.0 │
│ 1.0π │ 3.14159 │ 2.0 │
│ 1.5π │ 5.71239 │ 1.0 │
│ 2.0π │ 6.28319 │ 0.0 │
│ 2.5π │ 6.85398 │ 1.0 │
│ 3.0π │ 9.42478 │ 2.0 │
│ 3.5π │ 11.9956 │ 1.0 │
│ 4.0π │ 12.5664 │ 0.0 │
└──────┴──────────┴──────┘
UPDATE: corected according to Oscar_Smith suggestion to use sinpi
, cospi
1 Like
For rational fraction display take a look at this post.
1 Like
note that we have sinpi
and cospi
2 Likes
Thanks for the PrettyTables
suggestion