using Conda Conda.add("scipy") using PyCall PyCall.python, PyCall.pyversion so = pyimport("scipy.optimize") x₀ = so.newton(x -> cos(x) - x, 1) cos(x₀) - x₀ @time using PyPlot: PyPlot, plt x = range(-3π, 3π, length=400) plt.figure(figsize=(4,2)) @time plt.plot(x, sin.(x)) @time plt.plot(x, cos.(x)) plt.grid(ls=":") @time using SymPy: SymPy, sympy, Sym, @vars, PI, oo @vars x @vars a r positive=true I = sympy.Integral(exp(-a*x^r), (x, 0, oo)) display("text/html", raw"$$" * sympy.latex(I) * "=" * sympy.latex(I.doit().simplify()) * raw"$$") ]add Plots @time using Plots gr(legend=:bottomright, size=(600,200)) ## cutted(f) = f # safefuncを無効にすると縦に余計な線が入る cutted(f; M=5) = (x -> (y = f(x); abs(y) > M ? typeof(y)(NaN) : y)) interval = range(-5π, 5π, length=400) funcs = [sin, cos, tan, cot] @time plot(cutted.(funcs), interval, ylim=(-2, 2), label=["sin", "cos", "tan", "cot"]) using Base64 showgif(fn) = open(fn) do f b = base64encode(f) display("text/html", """""") end gr(size=(600, 200), legend=:bottomright) ENV["PLOTS_TEST"] = "true" interval = range(1, 20, length=100) @time anim = @animate for a in 2π*[interval; reverse(interval)] x = range(0, a, length=400) plot(x, [sin.(x), cos.(x)], label=["sin", "cos"], ylim=(-1.1, 1.1)) end gifname = "sin-cos.gif" gif(anim, gifname, fps = 15) sleep(0.1) showgif(gifname) ]add Distributions ]add StatsPlots ]add KernelDensity ]add RDatasets using Distributions using StatsPlots gr(legend=:topright, size=(400, 240)) normaldist = Normal(5.0, 3.0) # μ = 5.0, σ = 3.0 gammadist = Gamma(5.0, 0.7) # α = 5.0, θ = 0.7 @time plot([normaldist, gammadist], label=["Normal(5, 3)", "Gamma(5, 0.7)"]) ?Gamma μ = [1.0, 2.0] Σ = Float64[ 1 -1 -1 5 ] mvnormal = MvNormal(μ, Σ) using Plots using KernelDensity n = 1000 # サンプルサイズ X = rand(mvnormal, n) # 確率分布 mvnormal に従って乱数を生成 ik = InterpKDE(kde((X[1,:], X[2,:]))) pdfik(x,y) = pdf(ik,x,y) c = pdfik.(X[1,:], X[2,:]) pdfmvn(x,y) = pdf(mvnormal, [x,y]) # 確率分布 mvnormal の確率密度函数 xmin, xmax = minimum(X[1,:]), maximum(X[1,:]) ymin, ymax = minimum(X[2,:]), maximum(X[2,:]) x = range(xmin, xmax, length=200) y = range(ymin, ymax, length=200) z = pdfmvn.(x', y) gr(legend=false) P1 = plot(background_color_inside="gray", color=:thermal) plot!(xlim=(xmin,xmax), ylim=(ymin,ymax)) scatter!(X[1,:], X[2,:], zcolor=c, markersize=2, markerstrokewidth=0) P2 = heatmap(x, y, z, color=:thermal) P3 = contour(x, y, z, color=:thermal) plot(P1, P2, P3, size=(700, 200), layout=@layout([a b c])) using RDatasets using StatsPlots: @df school = RDatasets.dataset("mlmRev","Hsb82") ENV["LINES"] = 10 # 表示する最大行数を指定 display(school) ENV["LINES"] = 100; gr(size=(500, 250)) @df school density(:MAch, group=:Sx, legend=:topleft) gr(size=(640, 320)) @df school density(:MAch, group=(:Sx, :Sector), legend=:topleft, legendfontsize=7) ?@df ]add Nemo ]add Hecke using Nemo using Hecke n = 6 R, x = FlintQQ["x"] S, z = PowerSeriesRing(R, n+2, "z") Z = z + O(z^(n+2)) Bernoulli_Gen = divexact(Z*exp(x*Z), exp(Z)-1) Bernoulli_Nemo = @. factorial(BigInt[0:n;]) * coeff(Bernoulli_Gen, 0:n) Bernoulli_Str = (x->"$x").(Bernoulli_Nemo) Bernoulli_Expr = Meta.parse.(Bernoulli_Str) using SymPy: SymPy, sympy, Sym, @vars, PI, oo @vars x Bernoulli_Sym = eval.(Bernoulli_Expr) for k in 0:lastindex(Bernoulli_Sym)-1 display("text/html", raw"$$" * "B_{$k}(x) = " * sympy.latex(Bernoulli_Sym[k+1]) * raw"$$" ) end Qx, x = PolynomialRing(FlintQQ, "x") K, a = NumberField(x^2 - 10, "a") @time c, mc = class_group(K) @time A = ray_class_field(mc) @time K = number_field(A) @time ZK = maximal_order(K) @time isone(discriminant(ZK))