using SpecialFunctions using Printf using Plots pyplot() pyplotclf() = backend() == Plots.PyPlotBackend() && PyPlot.clf() cg(n, nmax) = cgrad(:lighttest)[1 - 0.85*n/nmax] [cg(n, 20) for n in 0:0.05:20] f(n, t) = sum((im*t)^k/factorial(k) for k in 0:n) t = range(0, 2π, length=400) nmax = 20 ns = [0;0; 0:nmax; nmax;nmax] @time anim = @animate for n in ns plot(size=(400, 410), aspect_ratio=1) plot!(fgcolor=:white, bgcolor=:black) plot!(xlim=(-2,2), ylim=(-2,2)) nstr = @sprintf("%2d", n) plot!(title="n = $nstr"; titlefontsize=10) z = f.(n, t) a = f.(n, π .* (0:0.5:1.5)) plot!(real(z), imag(z); label="", color=cg(n, nmax), lw=1.2) scatter!(real(a), imag(a); label="", color=cg(n, nmax), markerstrokecolor=cg(n, nmax)) end pyplotclf() gif(anim, "exp_it.gif", fps=2) f(n, t) = sum((im*t)^k/gamma(k+1) for k in 0:n) t = range(0, 6π, length=1000) nmax = 52 ns = [0;0; 0:nmax; nmax;nmax] @time anim = @animate for n in ns plot(size=(400, 410), aspect_ratio=1) plot!(fgcolor=:white, bgcolor=:black) plot!(xlim=(-2,2), ylim=(-2,2)) nstr = @sprintf("%2d", n) plot!(title="n = $nstr"; titlefontsize=10) z = f.(n, t) a = f.(n, π .* (0:0.5:5.5)) plot!(real(z), imag(z); label="", color=cg(n, nmax), lw=2, alpha=0.5) scatter!(real(a), imag(a); label="", color=cg(n, nmax), markerstrokecolor=cg(n, nmax), alpha=0.5) end pyplotclf() gif(anim, "exp_it_2.gif", fps=2) f(n, t; N=20) = exp(im*t) - sum(exp(k*(log(t)+im*(π/2)) - logabsgamma(k+1)[1]) for k in n+1:n+N) nmax = 20 fps = 20 ns = [fill(0.00, fps); 0.00:0.05:nmax; fill(nmax, fps)] t = range(0, 2π, length=400) @time anim = @animate for n in ns plot(size=(400, 410), aspect_ratio=1) plot!(fgcolor=:white, bgcolor=:black) plot!(xlim=(-2,2), ylim=(-2,2)) nstr = @sprintf("%5.2f", n) plot!(title="n = $nstr"; titlefontsize=10) z = f.(n, t) a = f.(n, π .* (0:0.5:1.5)) plot!(real(z), imag(z); label="", color=cg(n, nmax), lw=1.2) scatter!(real(a), imag(a); label="", color=cg(n, nmax), markerstrokecolor=cg(n, nmax)) end pyplotclf() gif(anim, "exp_it_smooth.gif", fps=fps) f(n, t; N=60) = exp(im*t) - sum(exp(k*(log(t)+im*(π/2)) - logabsgamma(k+1)[1]) for k in n+1:n+N) nmax = 52 fps = 20 ns = [fill(0.00, fps); 0.00:0.05:nmax; fill(nmax, fps)] t = range(0, 6π, length=1000) @time anim = @animate for n in ns plot(size=(400, 410), aspect_ratio=1) plot!(fgcolor=:white, bgcolor=:black) plot!(xlim=(-2,2), ylim=(-2,2)) nstr = @sprintf("%5.2f", n) plot!(title="n = $nstr"; titlefontsize=10) z = f.(n, t) a = f.(n, π .* (0:0.5:5.5)) plot!(real(z), imag(z); label="", color=cg(n, nmax), lw=2, alpha=0.5) scatter!(real(a), imag(a); label="", color=cg(n, nmax), markerstrokecolor=cg(n, nmax), alpha=0.5) end pyplotclf() gif(anim, "exp_it_smooth2.gif", fps=fps) cg_r(n, nmax) = cgrad(:lighttest)[n/nmax] [cg_r(n, 20) for n in 0:0.05:20] f(n, t; N=60) = exp(im*t) - sum(exp(k*(log(abs(t))+sign(t)*im*(π/2)) - logabsgamma(k+1)[1]) for k in n+1:n+N) nmax = 52 fps = 20 ns = [fill(0.05, fps); 0.05:0.05:nmax; fill(nmax, fps)] t = range(-10π, 10π, length=3142) u = range(-π, π, length=315) @time anim = @animate for n in ns plot(size=(600, 610), aspect_ratio=1) plot!(xlim=(-2,2), ylim=(-2,2)) nstr = @sprintf("%5.2f", n) plot!(title="n = $nstr"; titlefontsize=10)    w = exp.(im*u)   plot!(real(w), imag(w); label="", color=:black, lw=1.5) z = f.(n, t) plot!(real(z), imag(z); label="", color=cg_r(n, nmax), lw=2) end pyplotclf() gif(anim, "exp_it_smooth3.gif", fps=fps) cg_r(n, nmax) = cgrad(:darktest)[n/nmax] [cg_r(n, 20) for n in 0:0.05:20] f(n, t; N=60) = exp(im*t) - sum(exp(k*(log(abs(t))+sign(t)*im*(π/2)) - logabsgamma(k+1)[1]) for k in n+1:n+N) nmax = 52 fps = 20 ns = [fill(0.05, fps); 0.05:0.05:nmax; fill(nmax, fps)] t = range(-10π, 10π, length=3142) u = range(-π, π, length=315) @time anim = @animate for n in ns plot(size=(600, 610), aspect_ratio=1) plot!(xlim=(-2,2), ylim=(-2,2)) nstr = @sprintf("%5.2f", n) plot!(title="n = $nstr"; titlefontsize=10)    w = exp.(im*u)   plot!(real(w), imag(w); label="", color=:black, lw=1.5) z = f.(n, t) plot!(real(z), imag(z); label="", color=cg_r(n, nmax), lw=2) end pyplotclf() gif(anim, "exp_it_smooth4.gif", fps=fps)