Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Julia: A Fresh Programming Language for Freshmen (in Japanese)

A54ec7fe8d1697eb3ce3224109e5f45c?s=47 hsugawa8651
October 20, 2018

Julia: A Fresh Programming Language for Freshmen (in Japanese)

Presentation at JuliaTokyo #8 on October, 20, 2018.
https://juliatokyo.connpass.com/event/100780/

A54ec7fe8d1697eb3ce3224109e5f45c?s=128

hsugawa8651

October 20, 2018
Tweet

Transcript

  1. Julia: A Fresh Programming Language for Freshmen େֶ৽ೖੜʹ Julia Ͱԋश͢Δ

    ੁݪ ޺࣏ ट౎େֶ౦ژ γεςϜσβΠϯֶ෦ ػցγεςϜ޻ֶՊ (2018 ೥ൃ଍) Hiroharu Sugawara, Ph.D. Faculty of Systems Design, Tokyo Metropolitan University hsugawa@tmu.ac.jp ຊߨԋͷ಺༰͸ߨԋऀݸਓͷߟ͑ʹج͖ͮɺॴଐ૊৫ͷެࣜݟղͰ͸͋Γ·ͤΜ Julia Tokyo # 8 2018 ೥ 10 ݄ 20 ೔
  2. Julia: A Fresh Programming Language for Freshmen େֶ৽ೖੜʹ Julia Ͱԋश͢Δ

    ▶ ܦҢ ▶ 2018 ೥౓ վ૊ ▶ ळౙֶظ 1 ݶ 90 ෼ × 15 ि ▶ 1 ೥ֶ࣍ੜ ఆһ 90 ໊ ▶ ֶੜʹͱͬͯ࠷ॳͷϓϩάϥϛϯάԋशͷतۀ ▶ ߨԋऀʹͱͬͯ΋ɺॳΊͯͷ୲౰ ▶ तۀઃܭɾ໨࿦ݟ ▶ ४උ ▶ ڭࡐҊ঺հ ▶ Tips
  3. तۀઃܭɾ໨࿦ݟ ˕ ໨ඪ ▶ ࠓޙͷઐ໳ֶशʹ໾ཱͭ ▶ ࣗΒֶश͢Δ࢟੎Λᔻཆ͢Δ ʢActive Learningʣ ▶

    ڞ௨ͷٕ๏ʢScience, Technology, Engineering, Art and Mathematics ʣ ˕ ݱ࣮ɿେֶ 1 ೥࣍ ▶ PC ະशख़ ▶ ਺ֶɿະशख़ ... ߦྻ ˕ ࢖༻͢Δݴޠ΁ͷཁٻ ▶ ਺ֶه๏ͱͷ਌࿨ੑ ▶ ΍͘͞͠ਖ਼͍͠ݴޠ࢓༷ ▶ ͨͩͪʹ݁Ռ͕ಘΒΕΔ ▶ ಋೖ͕༰қ ▶ ແྉ ʷ ೔ຊޠςΩετ
  4. େֶӃ୲౰तۀͰࢼߦ ▶ 2017 ೥౓։ߨ ਺ࣜΛશͯάϥϑԽ͢Δ͜ͱΛ໨ࢦ͢ ▶ ϊʔτ PC Λڭࣨʹ࣋ࢀͤͨ͞ ▶

    ҎԼΛΠϯετʔϧ ▶ Julia v 0.6.4 ▶ IJulia ύοέʔδ Jupyter Notebook ▶ PyPlot ύοέʔδ: matplotlob ▶ Unitful ▶ Julia ݴޠͷςΩετ͸४උ͠ͳ͍ ֤ճतۀͰɺਵ࣌આ໌
  5. େֶӃतۀɾάϥϑඳըྫ ύϥϝʔλ ND , NA ʹରͯ͠ Vb = kB T

    e ln NAND n2 i w = √ 2ϵVb e ND + NA ND NA kB , T, ni , ϵ, e : ఆ਺ ee=1.602e-19 # C kbTe=1.38e-23 * 300 / ee # V ni=1e10 # cm^-3 vb(nap, ndp) = kbTe * log( nap .*ndp / ni^2) # V eps=8.854e-12*11.9 * 1e-2 # F/cm ww(nap, ndp) = sqrt(2*eps/ee .* vb.(nap, ndp) .* (nap .+ ndp) / (nap .* ndp )) # cm using PyPlot nD=logspace(15,18) for nA in [1e16, 5e16, 1e17, 5e17] # cm^-3 plot(nD, ww.(nD, nA) / 1e-7, label="nA="*string(nA)*" cm^-3" ) end legend() xscale("log") xlabel("nD / cm^-3") ylabel("w / nm")
  6. ४උɾ࡞ۀ೔ఔ ▶ तۀܭըॻ (γϥόε) : લ೥ 11 ݄ࠒ ▶ ʮखଓ͖ܕϓϩάϥϛϯάͷجຊԋशʯ

    ▶ ࢖༻ݴޠ͸໌هͤͣ ▶ ڭࣨ PC ؀ڥ࡞੒ґཔͱݕূɿຊ೥ 7ʙ8 ݄ ▶ Julia 0.6.4 ▶ Julia ύοέʔδɿ PyPlot, IJulia, DataFrames, CSV, ▶ PC ؀ڥ෮ݩπʔϧɿϑΝΠϧݩΠϝʔδͷ࡞੒ ▶ Windows10 ىಈυϥΠϒʹʮc:\JuliaʯΛ࡞੒ ▶ ެࣜόΠφϦΛར༻ɻJulia ίϚϯυϥΠϯ͔Β Pkg.add ˞ anaconda ੇ๏େ͖͍ɻ 4GB ऑɻ֤ϢʔβྖҬʹ͸ઃஔෆՄ ▶ Github Classroom ਃ੥ɿຊ೥ 7 ݄ ▶ ԋशςΩετ: ௚લ (ݱࡏਐߦத) ▶ ීஈ͔ΒωλΛߟ͑Δɻ Jupyter notebook ▶ Documenter.jl ͷར༻ ▶ 10 ݄͔Βελʔτ (3 ճ࣮ࢪࡁΈʣ
  7. ڭࡐҊɿಋೖ ୈ 1 ճ໨ ਺ͷ࢛ଇԋࢉ, ม਺, Range ܕ„ plot ؔ਺

    using PyPlot xs=-1:0.1:1 plot(xs, xs) ୈ 2 ճ໨ จࣈྻ„ άϥϑຌྫ, for จ using PyPlot xs=-1:0.1:1 for a in 1:5 plot(xs, a*xs, label="y="*string(a)*"x") end legend()
  8. ڭࡐҊ (த൫):ϞϯςΧϧϩ๏ʹΑΔਤܗ໘ੵͷਪఆ ϥϯμϜʹམͱͨ͠఺ͷ૯਺ͷ͏ͪɺ ਤܗͷதʹೖͬͨ఺ͷׂ߹Ͱɺ໘ੵΛਪఆ ཚ਺, if จ (for ϒϩοΫ಺) using

    PyPlot m=10 n=2^m s=0 for i=1:n x=rand() y=rand() if x*x + y*y <= 1 # ࢛෼ԁͷத c="r" s += 1 else c="b" end plot(x,y,".", color=c) end @show s/n @show pi/4 plt[:axes]()[:set_aspect]("equal") s / n = 0.791015625 pi / 4 = 0.7853981633974483
  9. ڭࡐҊ (த൫):਺஋ඍ෼ ුಈখ਺఺਺ ܻམͪɾ৘ใམͪ ఆٛʹجͮ͘਺஋ඍ෼ f ′(x) = lim h→0

    f (x + h) − f (x) h f (x) = xn (n = 1, 2, 3) x = 1 ʹ͓͚Δඍ܎਺ɻ ਖ਼ղ͸ f ′(x) = n using PyPlot h=logspace(-18,-8,100) for n=1:3 d=( (1+h).^n - 1) ./ h plot(h,d, ".", label="y=x^"*string(n)) end xlabel("h") ylabel("d") yscale("log") xscale("log") legend()
  10. ڭࡐҊ (த൫):ߦྻΛࣗࡏʹ࢖͏ ߦྻͷॳظԽɺ৐ࢉ julia> # ྻϕΫτϧΛฒ΂ͯߦྻʹ·ͱΊΔ xy=hcat([ [2*cos.(t); sin(t)] for

    t=0:pi/18:2pi]...) 2x37 Array{Float64,2}: 2.0 1.96962 1.87939 1.73205 ʜ 1.87939 1.96962 2.0 0.0 0.173648 0.34202 0.5 -0.34202 -0.173648 -2.44929e-16 julia> using PyPlot plot(xy[1,:], xy[2,:]) julia> r15=[ cosd(15) -sind(15); sind(15) cosd(15)] 2x2 Array{Float64,2}: 0.965926 -0.258819 0.258819 0.965926 julia> # ճసߦྻΛࠨ͔Β৐ͣΔ xy = r15 * xy plot(xy[1,:], xy[2,:])
  11. ڭࡐҊ (த൫):ઢܗ݁߹ɾઢܗࣸ૾ ϕΫτϧͷॳظԽɺࣸ૾ julia> u1=[1/2, 1/2]; u2=[1/2,-1/2]; julia> # ໘৺ฏ໘֨ࢠ

    xy1=hcat( [ i * u1 + j*u2 for i in 0:3, j in 0:3 ]... ) 2x16 Array{Float64,2}: 0.0 0.5 1.0 1.5 0.5 1.0 1.5 2.0 ʜ 2.0 2.5 0.0 0.5 1.0 1.5 -0.5 0.0 0.5 1.0 0.0 0.5 julia> r45=[cosd(45) -sind(45); sind(45) cosd(45)] julia> # ճసͱ֦େɹˠ੔਺ͷ֨ࢠ఺ʹॏͳΔ xy2=sqrt(2)*r45*xy1 2x16 Array{Float64,2}: 0.0 0.0 0.0 1.11022e-16 1.0 1.0 ʜ 2.0 3.0 0.0 1.0 2.0 3.0 0.0 1.0 3.0 1.11022e-16 julia> using PyPlot julia> plot( xy1[1,:], xy1[2,:], "bo") julia> plot( xy2[1,:], xy2[2,:], "r.") julia> plt[:axes]()[:set_aspect]("equal")
  12. ධՁ ▶ આ໌ΑΓ΋ɺ࣮ߦΛ༏ઌ͢Δํࣜͷԋश ˓ ֓Ͷ޷ධ ˞ άϥϑ͕ඳ͚Δɺ͙͢मਖ਼ͯ͠ࢼͤΔ ˚ ෆධͳडߨੜ΋... ҰࣈҰ۟ཧղ͔ͯ͠ΒਐΊ͍ͨ

    ӳޠจݙ͹͔Γɻ೔ຊޠͷઆ໌͕গͳ͍ɻ ▶ Julia ͸ણࡉɾΨϥεࡉ޻ Predefined ͕ͨ͘͞Μɻܯࠂͳ͘ॻ׵͑Մೳɻ ▶ ςΩετҊɻҎԼͰެ։ɻෆఆظʹߋ৽த https://hsugawa8651.github.io/memojuliav064/
  13. ڭࣨ PC ӡ༻্ͷ Tips ▶ anaconda ϥΠϒϥϦ͸େ͖͍ (࠶ܝ) ΠϯετʔϧɾσΟϨΫτϦΛγεςϜଆʹઃஔ Windows

    ͸ c:\Julia\0.64‘, c:\Julia\Pkg Λ४උ MacOSX ͸ ௐࠪத ▶ Jupyter notebook token ໰୊ ▶ github (classroom) ΞΫηεΛͣΒ͢ɻDoS attack ʹͳΒͳ͍Α͏ʹɺ
  14. ղ୊ɾ·ͱΊʹ୅͑ͯ ▶ Julia: A Fresh Approach to Numerical Computing https://julialang.org/publications/julia-fresh-approach-BEKS.pdf

    We introduce the Julia programming language and its design ʕ a dance between specialization and abstraction. ▶ Julia: A Fresh Programming Language for Freshmen (New wine in new vessels) Comprehensive and Powerful ϓϩάϥϛϯάಋೖʹ΋ͥͻ ... ೔ຊޠͷจݙ