Hi all,
I want to know whether my plot for \sin (|x|) is correct or not, this is the code:
using Plots, LaTeXStrings
gr()
function pitick(start, stop, denom; mode=:text)
a = Int(cld(start, π/denom))
b = Int(fld(stop, π/denom))
tick = range(a*π/denom, b*π/denom; step=π/denom)
ticklabel = piticklabel.((a:b) .// denom, Val(mode))
tick, ticklabel
end
function piticklabel(x::Rational, ::Val{:text})
iszero(x) && return "0"
S = x < 0 ? "-" : ""
n, d = abs(numerator(x)), denominator(x)
N = n == 1 ? "" : repr(n)
d == 1 && return S * N * "π"
S * N * "π/" * repr(d)
end
function piticklabel(x::Rational, ::Val{:latex})
iszero(x) && return L"0"
S = x < 0 ? "-" : ""
n, d = abs(numerator(x)), denominator(x)
N = n == 1 ? "" : repr(n)
d == 1 && return L"%$S%$N\pi"
L"%$S\frac{%$N\pi}{%$d}"
end
a, b = -4π, 4π
f(x) = sin(x)
g(x) = sin(abs(x))
plot(f,a,b, xtick=pitick(a, b, 2; mode=:latex), xlims=(-7,7), ylims=(-3,3),
bottom_margin = 10mm, label=L"f(x) = \sin(x)", framestyle = :zerolines,
legend=:outerright)
plot!(g,a,b, xtick=pitick(a, b, 2; mode=:latex), xlims=(-7,7), ylims=(-3,3),
bottom_margin = 10mm, label=L"g(x) = \sin (|x|)", framestyle = :zerolines,
legend=:outerright)
is it true to plot with code of sin(abs(x))
?