2022年12月9日 星期五

Wave Function

 Wave Function

2022/01/23

-----


https://pixabay.com/zh/photos/fishing-fisherman-sunset-sea-ocean-3062034/

-----

◎ 說明:

-----

◎ 參考資料:

-----

1. 波函數

-----

「波函數 Ψ(r, t) 是一種複值函數,表示粒子在位置 r、時間 t 的機率幅,它的絕對值平方是在位置 r、時間 t 找到粒子的機率密度。以另一種角度詮釋,波函數 Ψ(r, t) 是「在某時間、某位置發生交互作用的機率幅」。波函數的概念在量子力學裏非常基礎與重要,諸多關於量子力學詮釋像謎一樣之結果與困惑,都源自於波函數,甚至今天,這些論題仍舊尚未獲得滿意解答。」[2]。

-----

2. 波動力學

-----

「在 1920 年代與 1930 年代,理論量子物理學者大致分為兩個陣營。第一個陣營的成員主要為路易·德布羅意和埃爾溫·薛丁格等等,他們使用的數學工具是微積分,他們共同創建了波動力學。第二個陣營的成員主要為維爾納·海森堡和馬克斯·玻恩等等,使用線性代數,他們建立了矩陣力學。後來,薛丁格證明這兩種方法完全等價。」[2]。

-----

3. 波粒二象性

-----

「德布羅意於 1924 年提出的德布羅意假說表明,每一種微觀粒子都具有波粒二象性。電子也不例外,具有這種性質。電子是一種波動,是電子波。電子的能量與動量分別決定了它的物質波頻率與波數。既然粒子具有波粒二象性,應該會有一種能夠正確描述這種量子特性的波動方程式,這點子給予埃爾溫·薛丁格極大的啟示,他因此開始尋找這波動方程式。」[2]。

-----

4. 機率幅

-----

「1926 年,玻恩提出機率幅的概念,成功地解釋了波函數的物理意義。可是,薛丁格本人不贊同這種統計或機率方法,和它所伴隨的非連續性波函數塌縮,如同愛因斯坦認為量子力學只是個決定性理論的統計近似,薛丁格永遠無法接受哥本哈根詮釋。在他有生最後一年,他寫給玻恩的一封信內,薛丁格清楚地表明了這意見。」[2]。

-----

5. 狄拉克方程式

-----

「1928 年,保羅·狄拉克最先成功地統一了狹義相對論與量子力學,他推導出狄拉克方程式,適用於電子等等自旋為 1/2 的粒子。這方程式的波函數是一個旋量,擁有自旋性質。」[2]。

-----

References


[1] Wave function - Wikipedia

https://en.wikipedia.org/wiki/Wave_function


[2] 波函數 - 維基百科,自由的百科全書

https://zh.wikipedia.org/wiki/%E6%B3%A2%E5%87%BD%E6%95%B0

-----

2022年12月6日 星期二

Python Matplotlib(三)子圖

Python Matplotlib(三)子圖

2022/12/01

-----

References


[1] subplot 與 add_subplot 有何不同?

https://stackoverflow.com/questions/34442283/figure-add-subplot-vs-pyplot-subplot

-----

Matplotlib(目錄)

https://mandhistory.blogspot.com/2022/02/matplotlib.html

-----

Python Machine Learning(目錄)

https://mandhistory.blogspot.com/2022/05/python.html

-----

Python Matplotlib(二)細部元件

Python Matplotlib(二)細部元件

2022/11/22

-----


Fig. m2.1. Anatomy of a figure.

-----

代碼 m2.1


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Program m2.1:Anatomy of a figure
import numpy as np
import matplotlib.pyplot as plt

# plt.figure
fig = plt.figure(figsize=(16, 16))
ax = fig.add_subplot(111)

# ax.plot
x = np.linspace(0, 4, 100)
y1 = 3 + np.cos(x)
y2 = 1 - np.sin(x)
ax.plot(x, y1, lw='5')
ax.plot(x, y2, lw='5')

# ax.scatter
np.random.seed(12)
y_point = np.random.uniform(y1, y2, len(x))
ax.scatter(x, y_point, s=30, facecolor='white', edgecolor='black', linewidth=1)

# ax.set_title
ax.set_title('Anatomy of a figure', fontsize=40)

# ax.legend
ax.legend(['Blue cosine', 'Orange sine'], fontsize=30)
ax.text(3.54, 3.4, 'Legend', style='italic', fontsize=20, fontweight='bold')
ax.text(3.5, 3.25, 'ax.legend', fontsize=20)

ringstyle = dict(zorder=50, facecolor='None', clip_on=False)
ax.scatter(3.6, 3.6, s=700, edgecolor='white', linewidth=2, **ringstyle)
ax.scatter(3.6, 3.6, s=900, edgecolor='black', linewidth=1, **ringstyle)
ax.scatter(3.6, 3.6, s=1100, edgecolor='white', linewidth=2, **ringstyle)

# plt.savefig('/content/drive/My Drive/pml/m0002_01.png')
plt.show()

解說:


-----

References


[1] Quick start guide — Matplotlib 3.6.2 documentation

https://matplotlib.org/stable/tutorials/introductory/quick_start.html


[2] Getting Started with Matplotlib

https://www.skytowner.com/explore/getting_started_with_matplotlib


[3] Matplotlib Tutorial - Learn How to Visualize Time Series Data With Matplotlib and InfluxDB | InfluxData

https://www.influxdata.com/blog/matplotlib-tutorial-visualize-time-series-data-matplotlib-influxdb/


[4] Matplotlib.pyplot.subplots() in Python - GeeksforGeeks

https://www.geeksforgeeks.org/matplotlib-pyplot-subplots-in-python/


[5] matplotlib.axes.Axes.text — Matplotlib 3.6.2 documentation

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.text.html


[6] Matplotlib.axes.Axes.text() in Python - GeeksforGeeks

https://www.geeksforgeeks.org/matplotlib-axes-axes-text-in-python/


[7] Matplotlib的Anatomy of a figure復刻- 知乎

https://zhuanlan.zhihu.com/p/501009249

-----

Matplotlib(目錄)

https://mandhistory.blogspot.com/2022/02/matplotlib.html

-----

Python Machine Learning(目錄)

https://mandhistory.blogspot.com/2022/05/python.html

-----

Python Matplotlib(一)基本元件

Python Matplotlib(一)基本元件

2022/11/22

-----


Fig. 1.1. Basic components of Matplotlib.

-----

代碼 m1.1


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Program m1.1:Basic components of Matplotlib
import matplotlib as mpl
import matplotlib.pyplot as plt

mpl.rcParams['font.size'] = 80
fig = plt.figure(figsize=(16, 16))
ax = fig.add_subplot(111)

# figure
ax.plot([0, 0], [0, 100], 'b')       # left, [x1, x2], [y1, y2]
ax.plot([100, 100], [0, 100], 'b')   # right
ax.plot([0, 100], [0, 0], 'b')       # bottom

ax.plot([0, 30], [100, 100], 'b')    # top left
ax.plot([70, 100], [100, 100], 'b')  # top right
ax.text(35, 98, "Figure", color='b')

# axes 1
ax.plot([10, 10], [60, 90], 'r')     # left
ax.plot([90, 90], [60, 90], 'r')     # right
ax.plot([10, 90], [60, 60], 'r')     # bottom

ax.plot([10, 35], [90, 90], 'r')     # top left
ax.plot([65, 90], [90, 90], 'r')     # top right
ax.text(39, 85, "Axes", color='r')

# axes 2
ax.plot([10, 10], [10, 50], 'r')     # left
ax.plot([90, 90], [10, 50], 'r')     # right
ax.plot([10, 90], [10, 10], 'r')     # bottom

ax.plot([10, 35], [50, 50], 'r')     # top left
ax.plot([65, 90], [50, 50], 'r')     # top right
ax.text(39, 47, "Axes", color='r')

# axis
ax.plot([15, 85], [20, 20], 'g')     # x axis
ax.plot([20, 20], [15, 45], 'g')     # y axis
ax.text(70, 25, "x Axis", fontsize=30, color='g')
ax.text(25, 40, "y Axis", fontsize=30, color='g')

ax.set_axis_off()

# plt.savefig('/content/drive/My Drive/pml/m0001_01.png')
plt.show()

解說:


-----

# figure axes axis

[1] Getting Started with Matplotlib

https://www.skytowner.com/explore/getting_started_with_matplotlib


# rectangle

[2] How to Draw Rectangles in Matplotlib (With Examples)

https://www.statology.org/matplotlib-rectangle/

-----

Matplotlib(目錄)

https://mandhistory.blogspot.com/2022/02/matplotlib.html

-----

Python Machine Learning(目錄)

https://mandhistory.blogspot.com/2022/05/python.html

-----

一、Matplotlib(目錄)

Matplotlib (目錄)

2022/02/04

-----


https://pixabay.com/zh/photos/business-colleagues-communication-3605367/

-----

精華:


1. Matplotlib指南 - tw511教學網

2. 【Matplotlib 日本語訳】 TeXのネイティブレンダリング (Native TeX rendering) - Python Pyramid

3. Latex and Colab

-----

Matplolib 基礎

Python Matplotlib(一)基本元件

Python Matplotlib(二)細部元件

Python Matplotlib(三)子圖

-----

一、Matplotlib 入門一


1. Cheatsheets and Handouts


1.1. Cheatsheet - 1

1.1.1. Quick start

1.1.2. Anatomy of a figure

1.1.3. Subplots layout

1.1.4. Basic plots

1.1.5. Advanced plots

1.1.6. Scales

1.1.7. Projections

1.1.8. Lines

1.1.9. Markers

1.1.10. Colors

1.1.11. Colormaps

1.1.12. Tick locators

1.1.12. Tick formatters

1.1.13. Ornaments

1.1.14. Anamations

1.1.15. Styles

1.1.16. Quick reminders

1.1.17. Ten simple rules


1.2. Cheatsheet - 2

-----

二、Matplotlib 入門二


2.1. Handouts - Beginner

2.2. Handouts - Intermediate

2.3. Handouts - Tips

-----

三、Matplotlib 進階


先搞清楚 figure 與 axes 的區別,再搞清楚 axes 與 pyplot 的區別。

「如果有一些其他的細節調整,在搜索的時候,盡量選擇不用 plt 的答案。原則上來說,plt 和 ax 畫圖兩者是可以互相轉換的,然而轉換過程讓你的代碼更複雜,有時還會產生難以理解的 bug。因此畫圖的時候,請堅持使用一種格式。」[2], [3]。


3. Figure and Axes

3.1. Figure Class(3.1. matplotlib.figure)

3.2. Axes Class(3.2. matplotlib.axes)

3.3. Pyplot(3.3. matplotlib.pyplot、3.3.1. matplotlib.pyplot.figure、3.3.2. matplotlib.pyplot.axes)

-----

四、Matplotlib 深入


「Matplotlib 是一個綜合庫,用於在 Python 中創建靜態、動畫和交互式可視化。Matplotlib 讓簡單的事情變得簡單,讓困難的事情成為可能。」[1]。


4. Matplotlib


4.1. Layer

4.1.1. Scripting Layer

4.1.2. Artist Layer

4.1.2.1. Primitives

4.1.2.2. Containers

4.1.3. Backend Layer

4.1.3.1. FigureCanvas

4.1.3.2. Renderer

4.1.3.3. Event 

-----

References


# Python plotting

[1] Matplotlib: Python plotting — Matplotlib 3.3.4 documentation

https://matplotlib.org/


# plt fig ax

[2] matplotlib:先搞明白plt. /ax./ fig再畫- 知乎

https://zhuanlan.zhihu.com/p/93423829


# plt fig ax

[3] plt.xxx(), or ax.xxx(), That Is The Question In Matplotlib | Jun's blog

https://junye0798.com/post/plt-xxx-or-ax-xxx-that-is-the-question-in-matplotlib/

-----

Examples


# 虛線與變動頻率

matplotlib繪製sin、cos曲線_castingA3T的博客-CSDN博客

https://blog.csdn.net/castingA3T/article/details/78934947


# 波的分解與合成

matplotlib - Plotting sum of two sinusoids in Python - Stack Overflow

https://stackoverflow.com/questions/51926684/plotting-sum-of-two-sinusoids-in-python


# 振幅

Python how to plot graph sine wave - Stack Overflow

https://stackoverflow.com/questions/22566692/python-how-to-plot-graph-sine-wave


# 方波 2022/02/18

The Beginner Programmer: Fourier series and square wave approximation

http://firsttimeprogrammer.blogspot.com/2015/04/fourier-series-and-square-wave.html

-----

Matplotlib(目錄)

https://mandhistory.blogspot.com/2022/02/matplotlib.html

-----

Python Machine Learning(目錄)

https://mandhistory.blogspot.com/2022/05/python.html

-----

2022年12月2日 星期五

天下

天下

 CommonWealth

2022/10/29

-----

說明:

大部分為天下出版社的科普書籍,由直排改成橫排再版。

-----

(哲學)(科學)科學革命的結構

# 著者敘述:孔恩(Thomas S. Kuhn)著 ,程樹德,傅大為,王道還譯

https://webpacx.ksml.edu.tw/bookDetail/1604825


(哲學)理性之夢

https://webpacx.ksml.edu.tw/bookDetail/1560588


(科學)(傳記)愛因斯坦的辦公室給了誰?

# 《柏拉圖的天空》(本書改版前的書名)

https://webpacx.ksml.edu.tw/bookDetail/1571676


(物理)混沌

https://webpacx.ksml.edu.tw/bookDetail/1530834


(物理)(天文學)宇宙波瀾

https://webpacx.ksml.edu.tw/bookDetail/1522769


(化學)大師說化學

https://webpacx.ksml.edu.tw/bookDetail/1522824


(化學)(文學)週期表

https://webpacx.ksml.edu.tw/bookDetail/1535465


(生物)演化之舞

https://webpacx.ksml.edu.tw/bookDetail/1571705


(生物)(傳記)大自然的獵人

https://webpacx.ksml.edu.tw/bookDetail/1571949


(醫學)瘟疫與人

https://webpacx.ksml.edu.tw/bookDetail/1572661


(醫學)肝炎聖戰

https://webpacx.ksml.edu.tw/bookDetail/1571939


毛起來說無限

https://webpacx.ksml.edu.tw/bookDetail/1337182

https://webpacx.ksml.edu.tw/bookDetail/1370708


毛起來說三角

https://webpacx.ksml.edu.tw/bookDetail/166954

https://webpacx.ksml.edu.tw/bookDetail/1370709

https://webpacx.ksml.edu.tw/bookDetail/1349960


毛起來說e

https://webpacx.ksml.edu.tw/bookDetail/217883

https://webpacx.ksml.edu.tw/bookDetail/1349373

https://webpacx.ksml.edu.tw/bookDetail/1370710

-----

貓頭鷹


如何幫地球量體重 :史上最美的科學實驗

https://webpacx.ksml.edu.tw/bookDetail/27244

-----

Book List

https://mandhistory.blogspot.com/2022/08/book-list.html

-----

2022年12月1日 星期四

舊版草稿

 Python 量子運算(舊版草稿)

2022/12/01

-----


https://pixabay.com/zh/photos/censorship-limitations-610101/

-----

◎ 量子運算:

-----

Q1:量子運算最有名的演算法是?

A1:秀爾演算法。

「秀爾算法非常重要,因為它代表使用量子計算機的話,我們可以用來破解已被廣泛使用的公開密鑰加密方法,也就是 RSA 加密算法。」 [3]。

「The best-known algorithms are Shor's algorithm for factoring and Grover's algorithm for searching an unstructured database or an unordered list.」[4]。


Q2:有什麼合適的教程可以實作秀爾演算法?

A2:IBM 的 Qiskit [1] 與 Google 的 Cirq [2] 是兩大主流 [5]。Cirq 的開發者明確地聲明,希望使用者已經掌握「Quantum Computation and Quantum Information」這本經典教科書。比較起來,Qiskit 就顯得有親和力許多。

「This tutorial isn’t a quantum computing 101 tutorial, we assume familiarity of quantum computing at about the level of the textbook “Quantum Computation and Quantum Information” by Nielsen and Chuang.」[6]。

「Quantum Computation and Quantum Information is a textbook about quantum information science written by Michael Nielsen and Isaac Chuang, regarded as a standard text on the subject.」[7]。


Q3:秀爾演算法的基礎是什麼?

A3:量子相位估計。

「這個算法應用了量子傅里葉逆變換,同時作爲一個實用的基礎量子算法,又被應用在 Shor's algorithm(質因式分解算法),和 HHL algorithm(經常用於各種量子機器學習的最優化算法)等等算法中。」[8]。


Q4:量子相位估計的基礎是什麼?

A4:量子傅立葉變換、傅立葉變換、傅立葉級數、還有一些基礎的微積分跟線性代數。


Q5:哪些大學有不錯的線上量子運算課程?

Q5:Berkeley [9], [11]、University of California, Irvine [10]。

-----

Qiskit


1. Quantum States and Qubits


1.1 Introduction

1.2 The Atoms of Computation

1.3 Representing Qubit States

1.4 Single Qubit Gates

1.5 The Case for Quantum


2. Multiple Qubits and Entanglement


2.1 Introduction

2.2 Multiple Qubits and Entangled States

2.3 Phase Kickback

2.4 More Circuit Identities

2.5 Proving Universality

2.6 Classical Computation on a Quantum Computer


3. Quantum Protocols and Quantum Algorithms


3.1 Defining Quantum Circuits

3.2 Deutsch-Jozsa Algorithm

3.3 Bernstein-Vazirani Algorithm


3.4 Simon's Algorithm(QFT 的基礎)

3.5 Quantum Fourier Transform(QPE 的基礎)

3.6 Quantum Phase Estimation(Shor's Algorithm 與 HHL 的基礎)

3.7 Shor's Algorithm


3.8 Grover's Algorithm

3.9 Quantum Counting

3.10 Quantum Walk Search Algorithm


Quantum Machine Learning

4.1 Applied Quantum Algorithms

4.1.1 HHL(qPCA 與 qSVM 的基礎)

4.1.1.1 PCA(Principal Component Analysis)

4.1.1.2 qPCA(quantum Principal Component Analysis

4.1.1.3 SVM(Support Vector Machine)

4.1.1.4 qSVM(quantum Support Vector Machine

4.1.1.5 Quantum computing for finance: Overview and prospects

4.1.2 VQE

4.1.3 QAOA

4.1.4 Solving Satisfiability Problems using Grover's Algorithm

4.1.5 Hybrid quantum-classical Neural Networks with PyTorch and Qiskit


QRunes:CoinFlip 算法

-----

3.5.1 QFT 與 QPE 的基礎

-----

Discrete Fourier Transform(DFT) & Fast Fourier Transform(FFT)

3.5.1. Discrete Fourier Transform

3.5.1.1 The Basics of Waves(實作一)

3.5.1.2 Euler's Formula(實作二)

3.5.1.3 Roots of Unity(實作三)

3.5.1.4 DFT Matrix(實作四)

3.5.1.5. Discrete Fourier Transform in Python(實作五)

3.5.1.6 Fast Fourier Transform

3.5.1.7 Fast Fourier Transform in Python(實作六)


Fourier Transform Family(FS、FT、DFS、DTFT、DFT、FFT)

3.5.2 Fourier Transform Family


Fourier Series(FS)

3.5.3 Fourier Series

3.5.3.1 Circular Motion

3.5.3.2 Simple Harmonic Motion

3.5.3.3 Wave Function

3.5.3.4 Hilbert Space

3.5.3.5 Dot Product

3.5.3.6 Orthogonality

3.5.3.7 Convolution

3.5.3.8 Dirichlet Kernel

3.5.3.9 Complex Fourier Series

3.5.3.10 Fourier Series in Python

3.5.3.11 Square Wave in Python


Fourier Transform(FT)

3.5.4 Fourier Transform

3.5.4.1 Taylor Series

3.5.4.2 Euler's Formula

3.5.4.3 Euler's Number

3.5.4.4 Complex Number

3.5.4.4.1 Complex Number in Python

3.5.4.5 Radian

3.5.4.6 Eigenvalues and Eigenvectors

3.5.4.7 Unitary Matrix

3.5.4.8 Unitary Transformation

3.5.4.9 Orthogonal Matrix

3.5.4.10 Orthogonal Transformation


Discrete Fourier Series(DFS)

3.5.5 Discrete Fourier Series


Discrete Time Fourier Transform(DTFT)

3.5.6 Discrete Time Fourier Transform


Time / Frequency

Sampling

Laplace Transform

z Transform

Filter


Discrete Cosine Transform

Discrete Hilbert Transform

-----

◎ 量子運算基礎:

-----

Quantum Computing

3.5.7 Hardamard Gate

3.5.7.1 Hardamard Matrix

3.5.7.2 Hardamard Transform

3.5.7.3 Single Qubit

3.5.7.4 Superposition

3.5.7.5 Bloch Sphere

3.5.8 Controlled Phase Gate

-----

3.7.1 Shor's Algorithm 的基礎

-----

3.7.1 Euler's Theorem

3.7.2 Shor's Algorithm in C

-----

◎ 延伸閱讀:

-----

Quantum Computing Books

-----

Appendix A

「Qantum Protocols and Quantum Algorithms

3.1 Defining Quantum Circuits

3.2 Deutsch-Jozsa Algorithm

3.3 Bernstein-Vazirani Algorithm

3.4 Simon's Algorithm

3.5 Quantum Fourier Transform

3.6 Quantum Phase Estimation

3.7 Shor's Algorithm

3.8 Grover's Algorithm

3.9 Quantum Counting

3.10 Quantum Walk Search Algorithm

3.11 Quantum Teleportation

3.12 Superdense Coding

3.13 Quantum Key Distribution」[1]。

-----

Appendix B

「第 6 章 常用量子算法介紹及實現

6.1 QAOA 算法

6.2 Deutsch–Jozsa 算法

6.3 Grover 算法

6.4 HHL 算法

6.5 QuantumWalk 算法

6.6 Simon 算法

6.7 CoinFlip 算法

6.8 Bernstein-Vazirani 算法

6.9 QPE 算法

6.10 Shor 算法」[3]。

-----

Appendix C

Qiskit Certification

-----

References

# Qiskit

[1] Learn Quantum Computation using Qiskit

https://qiskit.org/textbook/preface.html


# Cirq

[2] Tutorials  |  Cirq  |  Google Quantum AI

https://quantumai.google/cirq/tutorials


# Quantum Algorithm

[3] QRunes — QRunes_tutorial documentation

https://qrunes-tutorial.readthedocs.io/en/latest/index.html


# Quantum Algorithm

[4] Quantum algorithm - Wikipedia

https://en.wikipedia.org/wiki/Quantum_algorithm


# Qiskit or Cirq

[5] (74) Should You Learn Cirq or Qiskit for Quantum Programming? - YouTube

https://www.youtube.com/watch?v=y69tg_eKHMU


[6] Cirq basics  |  Google Quantum AI

https://quantumai.google/cirq/tutorials/basics


# Standard Text

[7] Quantum Computation and Quantum Information - Wikipedia

https://en.wikipedia.org/wiki/Quantum_Computation_and_Quantum_Information


# QPE

[8] 量子相位分析算法 Quantum phase estimation algorithm - 台部落

https://www.twblogs.net/a/5c3f3957bd9eee35b3a6657c


# Berkeley 課程 Qubits, Quantum Mechanics, and Computers

[9] C191 Quantum information

https://inst.eecs.berkeley.edu/~cs191/fa14/


# University of California, Irvine

[10] CS 190/264, Fall 2018

https://www.ics.uci.edu/~irani/f18-quantum/index.html


# Berkeley 課程

[11] CS294-2, Spring 2007

https://people.eecs.berkeley.edu/~vazirani/quantum.html

-----

Python 量子運算(目錄)

https://mandhistory.blogspot.com/2022/01/quantum-computing.html

-----