Ogi
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 質問部屋 ```julia using Images using FFTW using NLsolve #テストするための画像を作る. u = zeros(128,128) #真っ黒な画像 # make a view img_a = @view u[1:128,24:48] #この行列を変化させると大元の行列も変えることができる. img_a = fill!(img_a, 1.0) img_b = @view u[1:128,72:96] img_b = fill!(img_b, 1.0) img_c = @view u[1:128,104:112] img_c = fill!(img_c, 1.0) img_d = @view u[40:70,1:128] img_d = fill!(img_d, 0.5) f = u #動かしたくない領域を参照するための行列 u #動かすための行列.こいつを更新していく dt = 0.05 e = 0.1 C1 = 300 C2 = 150000 lam = 50000 function nabla1(u) fftu = fft(u) fftu[1,:] = fftu[1,: ] * 0 for j in 1:63 fftu[j+1,: ] = (2 *pi *j *1im /128 ) * fftu[j+1 ,: ] fftu[129-j ,: ] = (2 *pi *(-j) *1im /128 )*fftu[129-j ,: ] end #j real(ifft(fftu)) end function nabla2(u) fftu = fft(u) fftu[: ,1 ] = fftu[: ,1 ] * 0 for k in 1:63 fftu[: ,k+1 ] = (2 *pi *k *1im /128 ) * fftu[: ,k+1 ] fftu[: ,129-k ] = (2 *pi *(-k) *1im /128 )*fftu[: ,129-k ] end #k real(ifft(fftu)) end function lap(u) #ラプラシアンの微分演算子. nabla1(nabla1(u)) + nabla2(nabla2(u)) end function lambda(u) #微分方程式に出てくるラムダの項を計算する関数.ok lamb =zeros(128,128) for i in 1:39 for j in 1:128 lamb[i,j] = lam * (f[i,j]-u[i,j]) end #j end #i for i in 71:128 for j in 1:128 lamb[i,j] = lam * (f[i,j]-u[i,j]) end #j end #i lamb end #function #NLsolveを用いる function nls(func, params...; ini = [0.0]) if typeof(ini) <: Number return nlsolve((vout,vin)->vout[1]=func(vin[1],params...), [ini]).zero[1] else return nlsolve((vout,vin)->vout .= func(vin,params...), ini).zero end end #nls(f,v,ini = u) #非線形ソルバーで解くために方程式のスキームを書いた. g(v)=(v -u)/dt + e * lap(lap(v)) - C1 * lap(v) + C2 * v -( lap((1/e) *4*(u^3) -6 * (u^2) + 2*u) + lambda(u) -C1 *(lap(u)) + C2*u) nls(g,v, ini = u) ``` 今書いてるやつ貼り付けますね おk これの最後で数値計算するんですがこけましたね 実行してみる。 どうでしたか? うん、エラーがでな 実行結果どうなりましたか ``` g (generic function with 1 method) ``` だね。 定義しただけで終わってませんかそれ たぶん ``` g(v) ``` を実行して終わった。 最後の行のnls()実行すれば計算がone step進められます. ごめん ``` nls(g,v, ini = u) ``` 忘れた。 あ,これだとvの定義忘れてます dane vの定義は v = uです おk vはu_nに対してu_{n+1}の意味です 現状こんな感じ(めんどうだからgistに上げた) ごめん、誤っていま消した。 もう一度発行する。 発行しなおした。 https://gist.github.com/muripoLife/500151545e6cb696a25314292d48a478 using NLsolve が抜けていますね https://gist.github.com/muripoLife/500151545e6cb696a25314292d48a478 いま、上げなおした。 エラーこれで同じ? これです.同じです じゃ、考えるか エラーコードの [12] (::var"#kw##nls")(::NamedTuple{(:ini,),Tuple{Array{Float64,2}}}, ::typeof(nls), ::Function, ::Array{Float64,2}) at ./none:0 にこけた原因が書かれてそうだと思いました(細かいところは読めてない.) ``` #NLsolveを用いる function nls(func, params...; ini = [0.0]) if typeof(ini) <: Number return nlsolve((vout, vin)->vout[1] = func(vin[1], params...), [ini]).zero[1] else return nlsolve((vout, vin)->vout .= func(vin,params...), ini).zero end end #nls(f,v,ini = u) ``` Numberって変数どこから出てきてる? ボスのサイトにあったやつを丸写ししました おk http://www.cas.cmc.osaka-u.ac.jp/~paoon/misc/julia/post/nlsolve-package/ このサイトです おk これ結構時間かかる? とりあえず、動いたみたいだけど、計算かえってこない 非線形方程式のソルバーなので時間はかかると思います. いま動かしているコード https://gist.github.com/muripoLife/500151545e6cb696a25314292d48a478 イテレーションごとにログ出ないの動いているかどうかわからんな これはどこを書き換えましたか? 最期を ``` nls(g, ini=u) ``` にしただけ 更新されているかどうかわからない…… デバックしやすいように書きなおそ 確かに実行はされていそうですね 実行はされて、メモリーが5000mbかかっているところしかみてない。 いわゆるデバッグってどうするんですか この場合、まずイテレーションごとに値プリントするとかかな? 今回は、gを高階関数で渡しているからかくの少し難しいかもね。 ??? ``` nls(g, ini=u) ``` gって関数でしょ。 関数を引数ように扱うのを高階関数というのよね。 合成関数とかがプログラミングで書きやすい的な。 なるほど nlsの定義の中にうまく書き込んだらいいのかなと思うのですがどうでしょうか それを試しているのだがうまく動かないね。 とりあえず長時間走らせてみます ok ワイもいろいろ書き換えてみるわ。 あとコード書いてるのjupyter? そうです 30分やっても終わらないですね おわらないね。 ちょいコードを考えておく。 ``` using Images using FFTW using NLsolve #種々のパラメーターのセッティング dt = 1.0 e = 0.8 C1 = 300.0 C2 = 150000.0 lam = 50000.0 #テストするための画像を作る. u = zeros(32,32) #真っ黒な画像 # make a view img_a = @view u[1:32,8:13] #この行列を変化させると大元の行列も変えることができる. img_a = fill!(img_a, 1.0) img_b = @view u[1:32,20:24] img_b = fill!(img_b, 1.0) img_c = @view u[1:32,27:30] img_c = fill!(img_c, 1.0) img_d = @view u[16:20,1:32] img_d = fill!(img_d, 0.5) f = u #動かしたくない領域を参照するための行列 #uを更新していく function nabla1(u) fftu = fft(u) fftu[1,:] = fftu[1,: ] * 0 for j in 1:15 fftu[j+1,: ] = (2 *pi *j *1im /32 ) * fftu[j+1 ,: ] fftu[33-j ,: ] = (2 *pi *(-j) *1im /32 )*fftu[33-j ,: ]   end #j  real(ifft(fftu)) end function nabla2(u) fftu = fft(u) fftu[: ,1 ] = fftu[: ,1 ] * 0 for k in 1:15 fftu[: ,k+1 ] = (2 *pi *k *1im /32 ) * fftu[: ,k+1 ] fftu[: ,33-k ] = (2 *pi *(-k) *1im /32 )*fftu[: ,33-k ] end #k  real(ifft(fftu)) end function lap(u) #ラプラシアンの微分演算子. nabla1(nabla1(u)) + nabla2(nabla2(u)) end function lambda(u) #微分方程式に出てくるラムダの項を計算する関数.ok lamb =zeros(32,32) for i in 1:15 for j in 1:32 lamb[i,j] = lam * (f[i,j]-u[i,j]) end #j end #i for i in 21:32 for j in 1:32 lamb[i,j] = lam * (f[i,j]-u[i,j]) end #j end #i lamb end #function #NLsolveを用いる function nls(func, params...; ini = [0.0]) if typeof(ini) <: Number return nlsolve((vout,vin)->vout[1]=func(vin[1],params...), [ini]).zero[1] else return nlsolve((vout,vin)->vout .= func(vin,params...), ini).zero end end #nls(f,v,ini = u) #非線形ソルバーで解くために方程式のスキームを書いた.vはuを1sステップ進めたもの g(v)=(v -u)/dt + e * lap(lap(v)) - C1 * lap(v) + C2 * v -( lap((1/e) *4*(u^3) -6 * (u^2) + 2*u) + lambda(u) -C1 *(lap(u)) + C2*u) for i in 1:10 @time u = nls(g, ini = u) end colorview(Gray,u) ``` ちゃんと動くようにはなりましたが,値にほぼ変化がないです.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully