2019年9月3日 星期二

第四章 解根_square well potential problem

Finding roots for transcendental equations

In this chapter, we will take "the square-well-potential problem" as an exercise of finding roots for transcendental equations with Python. Consider a potential well of width a and depth V0. Find the bound states and the corresponding energies.


The continuity of wave functions and their first order derivative at boundaries give us two transcendental equations. One for even wavefunctions and the other for odd wavefunctions.



It is important to make all of the quantities in a transcendental equation be dimensionless. By doing so, we can reduce the chance of making mistakes.
then, the transcendental equations become,
Let's plot them with Python3!  (source code)

For more details about this physical problem, chick this link.
不負責任der結尾   我要去屏東啦。剩下來的解根請見"Titus A. Beu, Introduction to Numerical Programming" ch 6.5  Newton's Method (書在書架上,他長這樣)
如果懶得自己寫解根程式,SciPy有一個不錯的套件  fsolve

2019年8月25日 星期日

第三章 ATOM -- An advanced code editor


  • 撰寫python程式的好所在 -- ATOM

     當初我在學Fortran 77的時候(沒錯!你沒聽錯,是f77),書逸學長教我用 CodeBlocks 這款編輯器,主要是因為安裝方便、好上手,它是我接觸的第一款編輯器。剛接觸 python 的時候我只會用python IDLE,python內建的整合開發環境。後來覺得 IDLE 的版面與字型不是很好看,就有了換編輯器的想法。在朋友的推薦下,我選擇了ATOM
  • IDE 與 code editor?
  1. IDE (Integrated Development Environment) [1]                                                                          整合開發環境:是用於提供程式開發環境的應用程式,一般包括程式碼編輯器、編譯器、偵錯程式和圖形使用者介面等工具。集成了程式碼編寫功能、分析功能、編譯功能、除錯功能等一體化的開發軟體服務套。所有具備這一特性的軟體或者軟體套(組)都可以叫整合開發環境。
  2. Code Editor                                                                                                                                  編輯器 : 程式碼編輯器,也可以說是文字編輯器,重點是:編輯器。幾乎所有編輯器都有自動縮排的功能,幾乎所有編輯器都沒有上面列出的IDE的其他功能。可以說,編輯器很純粹,就是用來編輯文字的。同時,幾乎每一種編輯器都支援外掛,你可以下載自己需要的、喜歡的地外掛(plug-in)。擁有外掛的編輯器不一定比IDE差。
延伸閱讀 : Top 5 IDEs and code editors for Python
  • 安裝 ATOM
step 1    到 ATOM 官網下載符合你的作業系統的最新的版本,載好後執行安裝檔。
step 2    安裝好就可以打開囉! ATOM的介面長這樣↓
  • 設定 ATOM 並執行 python 程式碼
ATOM 主頁 → File → Settings → Install → 搜尋 "platformio-ide-terminal"並安裝

把 Helloworld.py 叫出來吧(右鍵點檔案→開啟→以atom開啟) → 點一下主頁左下角的"加號"來開啟 terminal → PS 後面接的是程式碼所在的路徑 → 輸入 "python ./Helloworld.py" → 按 Enter 執行程式

註: "./" 代表的是目前所在的路徑,後面接你想要執行的python檔檔名

Reference:
https://makerpro.cc/2015/08/what-is-ide/

程式碼
========================================================================
Helloworld.py
print('Hello World!')



2019年8月22日 星期四

第二章 "Hello World" -- Python for the first time


  • 用Windows command(命令提示字元)

  1.  windows窗口鍵+R,輸入"cmd"把命令提示字元呼叫出來
  2.  輸入"python3",畫面就會顯示版本資訊
  3.  print('Hello World!')   屬於你的第一個python程式就誕生啦~

first time for Python
 p.s.  我用的是 Ubuntu ,不過它長得跟cmd很像,就將就一下吧

  • 用python內建的IDLE

  1.  當然也可以使用python內建的IDLE,在安裝python的資料夾可以找到它,打開後就會看到


補充: 我如何學習程式語言?
簡言之,「有什麼不會的,就去查。」
例如說,在"hello world!"程式中出現了以前沒看過函數 print(),不知道要怎麼用。這個時候立刻google搜尋 "python print" 就對了!


python是非常popular的程式語言,很多人在用就不怕沒人問。剛剛搜尋的結果,找到了一個不錯的網站:
 https://extenshu.com/2017/09/24/python%E5%88%9D%E5%AD%B8%E9%87%8D%E9%BB%9E-04-%E8%81%8A%E8%81%8Aprint/

除了有說明 print() 基本用法,還整理了一些print()小技巧!

========================================================================
這裡有幾個我推薦的網站
1. stack overflow
2. github
3. python官方說明網站
4. Django 筆記
5. [痞客邦] 我的小小AI天地
6. Numpy manual
7. Matplotlib Tutorial: Python Plotting



2019年8月21日 星期三

第一章 安裝Python與認識套件(packages)

  • Python教學 : 如何安裝 Python(Mac/Windows)

照著以下這個網站的說明一步一步把python安裝到電腦裡吧!

  • 在 Windows 上安裝 Numpy, Scipy packages

套件(packages)可以為我們完成許多事情,比如說繪圖、計算特殊函數等等,網路上有很多開放的資源。數值計算常用的套件有: NumPy, Scipy, Matplotlib...    以下網站有下載這些套件的完整教學
========================================================================
Easy way on windows [2]
  1. 建議安裝python3,目前3已經漸漸成為主流,到官網安裝最新版即可。https://www.python.org/downloads/
  2. pip是一個以Python電腦程式語言寫成的軟體包管理系統,他可以安裝和管理軟體包。pip可以用來安裝python的套件。
  3. 記得python資料夾中的Scripts的路徑加入至"環境變數"-Path中

註: "下載 tar.gz包,解壓縮',然後在命令行里進入解壓縮目錄,輸入python setup.py install,即可安装pip" 所謂輸入是指在解壓縮的目標資料中開啟cmd(命令提示字元),並輸入指令。 [在指定資料夾中開cmd]在檔案總管中,先按住 Shift,再在資料夾上按滑鼠右鍵,再鬆開 Shift。於彈出的選單中,按一下在此處開啟命令視窗。


========================================================================
Hard way on windows [3]


Reference:
[1]  Chun Yeung
[2]  milliele