cometscome / YukiNagai

Web site
1 stars 0 forks source link

1週間で学べる! Julia数値計算プログラミング(KS情報科学専門書)の誤植等の報告 #1

Open cometscome opened 2 years ago

cometscome commented 2 years ago

「1週間で学べる! Julia数値計算プログラミング(KS情報科学専門書)」の誤植や間違いは https://cometscome.github.io/YukiNagai/ja/books/greenjulia/ に報告していますが、もし他に見つけた方はこちらに書き込みしていただけると助かります。

DraScentET commented 2 years ago

3日目のアニメーション作成について p117で

x,v = get_xv(small,ith)
X,V = get_xv(large,ith)

とありますが、対応するget_xv(Ball,Int)(引数が二つのもの)が無いように思います。例えば、

function get_xv(ball::Ball, ith)  
    return ball.x_history[ith], ball.v_history[ith]  
end

のような追記が必要ではないでしょうか?

cometscome commented 2 years ago

コメントありがとうございます。確認しました。 その通りですね。申し訳ありません。定義しているつもりが抜けています。

DraScentET commented 2 years ago

4日目のところについて、私の誤解もあるかもしれませんが、気になったところを記します。

p130のcalc_psi内

nmax = length(bn)

nmax = length(cn)

p138

ai = bessj0zero[i]
aj = bessj0zero[j]

ai = besselj_zero(n,i)
aj = besselj_zero(n,j)

(あるいは、bessj0zeroをあらかじめ計算)

p138~139 calc_Vijの引数が(i,j,R)となっていますが、make_Hの中ではcalc_Vij(n,i,j,R,V)となっています。 前述のai,aj訂正をするなら、nが必要ですし、calc_Vij内のcalc_Vは書面上定義がなく、恐らくVを引数としているのでしょうから、 n,Vをそれぞれ引数に追加して、calc_V ⇒ Vとするのではないでしょうか? また、 test4内で、

V(r) = 2 * exp(-(r-R/r)^2/(R/20)^2)

となっていますが、calc_Vij内のcalc_Vは引数を二つ取ります。なので、V(r,R)としてcalc_Vijの最後の引数として渡すのだと思います。(トータルでいうとcalc_Vやbessj0zeroなどをグローバル変数的に使うのか、引数にするのかのコードが混在しているように見えます……)

p141の何も考えない方法(4.3.1)で、make_H!が使われていますが、make_H!の定義がでてくるのは、疎行列を使う方法のところ(4.3.2)からなので、順番にやっていると、ここで詰まります。

DraScentET commented 2 years ago

〇小さいことですが、p130のmake_Hk内の13行目v += Ukkpv += Vkkpの誤りではないでしょうか?

〇juliaやPlotsのバージョンの問題かもしれませんが、p161のコードはそのままだと動かず、 using Plots.PlotMeasures を追加する必要があるかと思います(mmの定義の読み込みため)。

〇p173でmontecarlo_fastを使っていて、書き換えについてはp172にて説明があります。ただ、元もとのmontecarloの戻り値が2つですが、montecarlo_fast戻り値(3つ)の変更については、特に言及がありません。そのため、p172で説明されている内容ではp173のコードは動きません(ただし、先のページp175には戻り値3つのコードになっているため、そこまで読めば修正可能です)。特に戻り値についての言及はないかと思うので、おそらく、p170の内容が意図と異なっていて(修正忘れ?)、montecarloの戻り値を

return mz_data, accept_count/(num_total*Lx*Lz), absmz_meanvalue/measure_count

としたうえで、p171のtestも戻り値を3つ受けるようにしてあった?のかと思いましたのでこちらも報告します。

cometscome commented 2 years ago

指摘ありがとうございます。大変助かります。今確認できませんが、近いうちに必ずチェックしたいと思います

DraScentET commented 2 years ago

〇p170のmontecalro関数の引数で、measure_intervalとなるべきところが、$\rm{ measure_interval}$となっています。

〇p210のOptimの使用例で、 optimize(f, [0.0, 0.0])a1 = optimize(f, [0.0, 0.0]) だと思います。

〇p231~p232でtestint/testfloatのチェックをしていますが、nの設定(n=1000など)が抜けています。

cometscome commented 2 years ago

@DraScentET 修正コメントありがとうございます。大変助かります。全てチェックして、反映させました。

DraScentET commented 2 years ago

@cometscome お疲れ様です。最後までやり切りましたが、私が気づいたところはほとんど書いたと思います。 あと、これは「ミスではない」と判断しているのですが、「using Plots」「using LinearAlgebra」等が書面になく、自主的に補う必要があるところは多数あります。初出時に説明しているので、なくても「自主的に入れられて当然」とは思いますが、あったほうが親切かもしれません。(未定義エラーが出るので、慣れた人ならすぐ直せますが……)

ここでは、問題点ばっかり指摘するコメントになってしまったのですが、全体を通して本書で大変勉強になりました。ありがとうございました。

nariz7 commented 2 years ago

1つ1つ打ち込んで楽しみながら本書を読んでいます。 p190 calc_ldos(E,i,ene,ψ,η) 内の4行目、ldos += abs(ψ[i,n]^2*η/((E-ene[n])^2+η^2))とすべきところの最後の閉じ括弧が抜けていました。エラーを出さず次のldos_plot()の結果が変になるものだったのでご報告いたします。

cometscome commented 2 years ago

ありがとうございます。返信が遅れており申し訳ありません。確認してみます。

phasetr commented 2 years ago

エラー報告

環境

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.2.0)
  CPU: Apple M1 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, cyclone)

概要

https://cometscome.github.io/YukiNagai/ja/books/05_2_1_7.ipynbをJulia1.7.2で確認したところ次のエラーが出ました。 montecarlo直下のtestの実行結果で次のように出ます。

The function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.

Stacktrace:
  [1] #_make_hist#213
    @ ~/.julia/packages/Plots/lW9ll/src/recipes.jl:842 [inlined]
  [2] macro expansion
    @ ~/.julia/packages/Plots/lW9ll/src/recipes.jl:854 [inlined]
  [3] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{Val{:barhist}}, x::Any, y::Any, z::Any)
    @ Plots ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:289
  [4] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:50
  [5] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:60
  [6] _process_seriesrecipes!(plt::Any, kw_list::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:27
  [7] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/RecipesPipeline.jl:97
  [8] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/lW9ll/src/plot.jl:209
  [9] #plot#145
    @ ~/.julia/packages/Plots/lW9ll/src/plot.jl:91 [inlined]
 [10] #histogram#435
    @ ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:410 [inlined]
 [11] test()
    @ Main ./In[10]:12
 [12] top-level scope
    @ In[10]:16
 [13] eval
    @ ./boot.jl:373 [inlined]
 [14] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1196

test_tdeptest_animeでも同じようなエラーが出ています。全て比較しきったわけではありませんが、少なくともThe function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.は共通です。

test_tdep

The function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.

Stacktrace:
  [1] #_make_hist#213
    @ ~/.julia/packages/Plots/lW9ll/src/recipes.jl:842 [inlined]
  [2] macro expansion
    @ ~/.julia/packages/Plots/lW9ll/src/recipes.jl:854 [inlined]
  [3] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{Val{:barhist}}, x::Any, y::Any, z::Any)
    @ Plots ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:289
  [4] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:50
  [5] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:60
  [6] _process_seriesrecipes!(plt::Any, kw_list::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:27
  [7] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/RecipesPipeline.jl:97
  [8] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/lW9ll/src/plot.jl:209
  [9] #plot#145
    @ ~/.julia/packages/Plots/lW9ll/src/plot.jl:91 [inlined]
 [10] #histogram#435
    @ ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:410 [inlined]
 [11] test_tdep()
    @ Main ./In[12]:16
 [12] top-level scope
    @ In[13]:1
 [13] eval
    @ ./boot.jl:373 [inlined]
 [14] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1196

test_anime

The function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.

Stacktrace:
  [1] #_make_hist#213
    @ ~/.julia/packages/Plots/lW9ll/src/recipes.jl:842 [inlined]
  [2] macro expansion
    @ ~/.julia/packages/Plots/lW9ll/src/recipes.jl:854 [inlined]
  [3] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{Val{:barhist}}, x::Any, y::Any, z::Any)
    @ Plots ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:289
  [4] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:50
  [5] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:60
  [6] _process_seriesrecipes!(plt::Any, kw_list::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:27
  [7] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/RecipesPipeline.jl:97
  [8] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/lW9ll/src/plot.jl:209
  [9] #plot#145
    @ ~/.julia/packages/Plots/lW9ll/src/plot.jl:91 [inlined]
 [10] #histogram#435
    @ ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:410 [inlined]
 [11] test_anime()
    @ Main ./In[15]:13
 [12] top-level scope
    @ In[15]:17
 [13] eval
    @ ./boot.jl:373 [inlined]
 [14] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base ./loading.jl:1196
cometscome commented 2 years ago

報告ありがとうございます。 こちら

Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin21.4.0)
  CPU: Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, westmere)
Environment:
  JULIA_SSL_NO_VERIFY_HOSTS = github.com

で確認しましたが、エラーを再現できていません。1.7.1でも確認しました。問題なく動いています。 jupyter notebookではなく、05_2_1_7.jlファイルの方をダウンロードして

julia 05_2_1_7.jl

として実行し、それでもエラーが出るか確認していただけますか?

phasetr commented 2 years ago

同タイプのエラーが出ました。 後でwindows機でも検証してみます。

ERROR: LoadError: The function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.
Stacktrace:
  [1] #_make_hist#213
    @ ~/.julia/packages/Plots/lW9ll/src/recipes.jl:842 [inlined]
  [2] macro expansion
    @ ~/.julia/packages/Plots/lW9ll/src/recipes.jl:854 [inlined]
  [3] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{Val{:barhist}}, x::Any, y::Any, z::Any)
    @ Plots ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:289
  [4] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:50
  [5] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:60
  [6] _process_seriesrecipes!(plt::Any, kw_list::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:27
  [7] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/RecipesPipeline.jl:97
  [8] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/lW9ll/src/plot.jl:209
  [9] #plot#145
    @ ~/.julia/packages/Plots/lW9ll/src/plot.jl:91 [inlined]
 [10] #histogram#435
    @ ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:410 [inlined]
 [11] test()
    @ Main ~/Downloads/05_2_1_7.jl:132
 [12] top-level scope
    @ ~/Downloads/05_2_1_7.jl:136
phasetr commented 2 years ago

Windowsでも次のようなエラーが出ました。 勉強会で眺める予定だったので勉強会参加者にもどうなっているか聞いてみます。

環境

julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, znver1)

エラー

The function body AST defined by this @generated function is not pure. This likely means it contains a closure, a comprehension or a generator.

Stacktrace:
  [1] #_make_hist#229
    @ C:\Users\phasetr\.julia\packages\Plots\Ye1xf\src\recipes.jl:836 [inlined]
  [2] macro expansion
    @ C:\Users\phasetr\.julia\packages\Plots\Ye1xf\src\recipes.jl:848 [inlined]
  [3] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{Val{:barhist}}, x::Any, y::Any, z::Any)
    @ Plots C:\Users\phasetr\.julia\packages\RecipesBase\3fzVq\src\RecipesBase.jl:283
  [4] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline C:\Users\phasetr\.julia\packages\RecipesPipeline\Bxu2O\src\series_recipe.jl:50
  [5] _process_seriesrecipe(plt::Any, plotattributes::Any)
    @ RecipesPipeline C:\Users\phasetr\.julia\packages\RecipesPipeline\Bxu2O\src\series_recipe.jl:60
  [6] _process_seriesrecipes!(plt::Any, kw_list::Any)
    @ RecipesPipeline C:\Users\phasetr\.julia\packages\RecipesPipeline\Bxu2O\src\series_recipe.jl:27
  [7] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline C:\Users\phasetr\.julia\packages\RecipesPipeline\Bxu2O\src\RecipesPipeline.jl:97
  [8] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots C:\Users\phasetr\.julia\packages\Plots\Ye1xf\src\plot.jl:208
  [9] #plot#159
    @ C:\Users\phasetr\.julia\packages\Plots\Ye1xf\src\plot.jl:91 [inlined]
 [10] #histogram#408
    @ C:\Users\phasetr\.julia\packages\RecipesBase\3fzVq\src\RecipesBase.jl:404 [inlined]
 [11] test()
    @ Main .\In[10]:12
 [12] top-level scope
    @ In[10]:16
 [13] eval
    @ .\boot.jl:373 [inlined]
 [14] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
    @ Base .\loading.jl:1196
cometscome commented 2 years ago

ありがとうございます。エラーを見た感じ私のコードではなくてPlotsのエラーのようです。 Plotsのバージョンはわかりますでしょうか。最新でしょうか? パッケージモードでupdate Plotsをやったあとにもう一度試してもらえますか?

phasetr commented 2 years ago

@cometscome ここで報告したエラーは私の環境依存の問題でした。パッケージを全削除の上、必要なパッケージだけインストールした最小構成で試して、エラーが出ないことは確認しました。お手数おかけしました。

cometscome commented 2 years ago

@cometscome ここで報告したエラーは私の環境依存の問題でした。パッケージを全削除の上、必要なパッケージだけインストールした最小構成で試して、エラーが出ないことは確認しました。お手数おかけしました。

了解しました。動いたようでよかったです。

25NightBattle commented 1 year ago

4日目の途中まで読んだのですが、まだウェブページに反映されていない誤植があるようなので報告いたします。

○p.130 微分方程式をベッセルの微分方程式に似せるための変数変換を r = r' sqrt(E)としていますが、正しくは r' = r sqrt(E) かと思います。

○p.130 上の変数変換後の微分方程式で、第3項と第4項に誤りがあり、正しくは 第3項: ( r' - n^2 ) ξ(r') -> ( {r'}^2 - n^2 ) ξ(r') (2乗が抜けている) 第4項: - {r'}^2 / E V(r) -> - {r'}^2 / E V(r') (Vの引数がr'でなくrのまま) かと思います。

○p.138 採用するポテンシャルは V(r) = 2exp(-(r-R/4)^2 / (R/20) ) ではなく V(r) = 2exp(-(r-R/4)^2 / (R/20)^2 )かと思います。test4() 内ではきちんと(R/20)が2乗されています。

cometscome commented 1 year ago

読んでいただきありがとうございます。133ページのベッセル関数の式変形、おっしゃる通りでした。 138ページも確認しました。 指摘ありがとうございます。助かります。

m-ochiai-git commented 1 year ago

150ページのトンネル効果の図ですが,粒子の存在確率が1に規格化されていません。149ページのコード11行目の空間刻み幅 dx の定義が誤りではないでしょうか。 既に指摘ありましたら申し訳ありません。

gyu-don commented 12 months ago

p.66 の get_subtypes の4行目は、 if length(types) > 1 よりも if length(types) > 0 が適切に思われます。 書籍に出ている Integer の例ではどちらでも同じ結果となりますが、サブタイプを1つ持つ型が含まれている場合、すべてのサブタイプが列挙されません。

入力例:

abstract type T end
abstract type Ta  <: T end
abstract type Taa <: Ta end
abstract type Tab <: Ta end
abstract type Taba <: Tab end
abstract type Tb  <: T end
abstract type Tba <: Tb end

get_subtypes(T, 1)

期待する出力:

  Ta
   Taa
   Tab
    Taba
  Tb
   Tba
Any[]

実際の出力:

  Ta
   Taa
   Tab
  Tb
1-element Vector{Any}:
 Tba
gyu-don commented 10 months ago

第1刷 p.121 下から5行目 2iC_1 sin [i √εL] は、 2iC_1 sin [√εL] と思われます (sinの中に i が入らない)

cometscome commented 1 month ago

みなさま、ご報告していただきありがとうございます。それぞれ、確認したいと思います。返信が遅くなり申し訳ありませんでした。