<style> .markdown-body table{ display: unset; } </style> # SciDAVis 教學 2:作圖技巧及化直 > 作者:王一哲 > 日期:2019/12/4 <br /> ## 作圖原則 1. 假設自變數為$x$、應變數為$y$,先畫出$y-x$關係圖,如果數據點看起來分布在一條斜直線上,利用線性迴歸畫出最接近直線,計算斜率、截距及其不準量;如果數據點看起來是分布在一條曲線上則進行步驟2。 2. 計算 $\log x$、$\log y$,畫出$\log y - \log x$關係圖,如果數據點看起來分布在一條斜直線上,利用線性迴歸畫出最接近直線,計算斜率、截距及其不準量,其中斜率可以代表$x$、$y$取幾次方時兩者的關係為線性。假設$x$、$y$數學關係為 $$y^m = kx^n$$ $$m \log y = \log k + n \log x$$ $$\log y = \frac{n}{m} \log x + \frac{\log k}{m}$$ 因此$\log y - \log x$關係圖的最接近直線斜率為$n/m$。 3. 計算 $x^n$、$y^m$,畫出$y^m - x^n$關係圖,如果數據點看起來分布在一條斜直線上,利用線性迴歸畫出最接近直線,計算斜率、截距及其不準量。 <br /> ## 自由落下時間與高度關係圖 假設小球原為靜止、離地面高度為$h$、受到重力作用開始落下,只考慮重力的作用,重力加速度$g = 9.8~\mathrm{m/s^2}$,小球在空中飛行時間為$t$、飛行時間不準量為$errt$,實驗數據如下 ```python h(m),t(s),errt(s) 2,0.65,0.01 4,0.89,0.01 6,1.11,0.01 8,1.27,0.01 10,1.42,0.01 12,1.57,0.01 14,1.71,0.01 16,1.79,0.01 18,1.92,0.01 20,2.03,0.01 ``` <br /> 先畫出$t - h$關係圖,發現數據點應該是分布在一條曲線上,無法進行線性擬合。 <img height="60%" width="60%" src="https://imgur.com/MxhB59i.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">t - h 關係圖</div> <br /> 接下來計算$\log t$、$\log h$,先在資料表中插入兩個空的欄位 <img height="50%" width="50%" src="https://imgur.com/G9CTu7l.png" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">插入空的欄位</div> <br /> 為了避免空白列中的東西影響到公式計算結果,最好能移除多餘的列。 <img height="40%" width="40%" src="https://imgur.com/dIj9kuH.png" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">移除多餘的列</div> <br /> 選取空的欄位後,按右方的第3個分頁**Formula**,接著輸入公式 ```python log10(col("h")) ``` 按下右上角的**Apply**套用公式,就可以計算欄位h當中所有數值的log值,再用同樣的方法計算欄位t當中所有數值的log值。 <img height="80%" width="80%" src="https://imgur.com/rS1uusL.png" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">輸入公式計算 log h</div> <br /> 畫出$\log t - \log h$關係圖,數據點看起來分布在一條斜直線上,線性擬合的結果為 $斜率 = 0.498075643829331 \pm 0.00468005995555611$ $截距 = -0.343035081717925 \pm 0.00469657969413444$ $R^2 = 0.999294177388029$ 可以推測$t - \sqrt h$關係圖的數據點應該會分布在一條斜直線上。 <img height="60%" width="60%" src="https://imgur.com/ZjErdua.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">log t - log h 關係圖</div> <br /> 計算$\sqrt h$,畫出$t - \sqrt h$關係圖,線性擬合的結果為 $斜率 = 0.453008971741022 \pm 0.00332681637115833$ $截距 = -0.00343345881140915 \pm 0.0110338016495439$ $R^2 = 0.999330244635544$ <img height="60%" width="60%" src="https://imgur.com/ENaDuxc.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">t - 根號h 關係圖</div> <br /> 自由落下物體飛行時間與高度的理論關係式為 $$h = \frac{1}{2}gt^2 ~\Rightarrow~ t = \sqrt{\frac{2h}{g}}$$ 因此$t - \sqrt h$關係圖最接近直線斜率理論值 $\approx 0.452$,百分誤差 $\approx 0.22\%$。 <br /> ## 雙狹縫干涉條紋寬度與縫距關係圖 假設雙狹縫的縫距為$d$、干涉條紋寬度為$y$、干涉條紋寬度不準量為$erry$,實驗數據如下 ```python d(mm),y(mm),erry(mm) 0.10,6.2,0.1 0.20,3.0,0.1 0.30,2.2,0.1 0.40,1.5,0.1 0.50,1.3,0.1 ``` <br /> 先畫出$y - d$關係圖,發現數據點應該是分布在一條曲線上,無法進行線性擬合。 <img height="60%" width="60%" src="https://imgur.com/6XgpsZl.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">y - d 關係圖</div> <br /> 接下來計算$\log y$、$\log d$,畫出$\log y - \log d$關係圖,數據點看起來分布在一條斜直線上,線性擬合的結果為 $斜率 = -0.976177616265074 \pm 0.0258646761462483$ $截距 = -0.187476038836598 \pm 0.0164029222944223$ $R^2 = 0.997898332775322$ 可以推測$y - 1/d$關係圖的數據點應該會分布在一條斜直線上。 <img height="60%" width="60%" src="https://imgur.com/zCXlghM.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">log y - log d 關係圖</div> <br /> 計算$1/d$,畫出$y - 1/d$關係圖,線性擬合的結果為 $斜率 = 0.613859556494192 \pm 0.0154140324718516$ $截距 = 0.036708025343189 \pm 0.083395787930577$ $R^2 = 0.997991740579429$ <img height="60%" width="60%" src="https://imgur.com/RMEHEKY.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">y - 1/d 關係圖</div> <br /> 雙狹縫干涉條紋寬度與狹縫縫距的理論關係式為 $$y = \frac{\lambda L}{d}$$ 其中$\lambda$為波長、$L$為狹縫到屏幕的距離,這裡使用的實驗數據為$\lambda = 633 ~\mathrm{nm} = 6.33 \times 10^{-4} ~\mathrm{mm}$、$L = 1 ~\mathrm{m} = 1 \times 10^3 ~\mathrm{mm}$,因此$y - 1/d$關係圖最接近直線斜率理論值 $= 0.633$,百分誤差 $\approx -3\%$。 <br /> ## 克卜勒第三行星運動定律 從網路上可以找到行星公轉軌道的資料,為了簡化數值,半長軸$a$的單位為天文單位 (astronomical units, AU),公轉週期$T$的單位為地球年 (yr)。 <div style="text-align:center"> | 行星 | 公轉週期<i>T</i> (yr) | 半長軸 <i>a</i> (AU) | | ------ | ----- | ----- | | 水星 | 0.241 | 0.387 | | 金星 | 0.615 | 0.723 | | 地球 | 1.000 | 1.000 | | 火星 | 1.881 | 1.524 | | 木星 | 11.862| 5.203 | | 土星 | 29.458| 9.555 | | 天王星 | 84.022 | 19.218 | | 海王星 | 164.774 |30.110 | </div> <br /> 先畫出$a - T$關係圖,發現數據點應該是分布在一條曲線上,無法進行線性擬合。 <img height="60%" width="60%" src="https://imgur.com/Ha2OVOD.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">a - T 關係圖</div> <br /> 接著再試著畫 $\log a - \log T$ 關係圖,圖中的數據點分布在一條直線上,線性擬合結果為 $斜率 = 0.666684934333627 \pm 0.000036181210991$ $截距 = 0.000015083250878 \pm 0.000045138730909$ $R^2 = 0.999999963819$ 可以推測$a^3 - T^2$關係圖的數據點應該會分布在一條斜直線上。 <img height="60%" width="60%" src="https://imgur.com/FC6FiSL.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">log a - log T 關係圖</div> <br /> 計算$a^3$、$T^2$,畫出 $a^3 - T^2$ 關係圖,線性擬合結果為 $斜率 = 0.999968855984298 \pm 0.000005447763279$ $截距 = 0.102263315181479 \pm 0.0543289671454164$ $R^2 = 0.99999999982192$ 由於單位採用 AU 及 yr,最接近直線的斜率會很接近1。 <img height="60%" width="60%" src="https://imgur.com/96V9fDS.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">a<sup>3</sup> - T<sup>2</sup> 關係圖</div> <br /> 由於上圖中資料點對應的數值較大,坐標軸旁邊標示的數字太多,看起來很雜亂,這時我們會將$a^3$和$T^2$的數值同除以某個倍數再作圖。假設倍數為1000,則單位改為 $\times 10^3 ~\mathrm{AU}$ 及 $\times 10^3 ~\mathrm{yr}$,圖片看起來會比較精簡。 <img height="60%" width="60%" src="https://imgur.com/mZytFfn.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">a<sup>3</sup> - T<sup>2</sup> 關係圖(單位改為1000倍)</div> <br /> ## 折射定律 當光從折射率為$n_1$的介質射向折射率為$n_2$的介質時,若$n_2 > n_1$,折射光會偏向法線,也就是入射角$\theta_1$小於折射角$\theta_2$,實驗數據如下表。 <br /> <img height="35%" width="35%" src="https://imgur.com/etwIda2.png" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">折射定律示意圖</div> <br /> <div style="text-align:center"> | 入射角 $\theta_1 ({}^{\circ})$ | 折射角 $\theta_2 ({}^{\circ})$ | | ----------------------- | ----------------------- | | 10 | 8 | | 20 | 15 | | 30 | 22 | | 40 | 29 | | 50 | 35 | | 60 | 40 | | 70 | 45 | | 80 | 48 | </div> <br /> 先畫出$\theta_1 - \theta_2$關係圖,發現數據點應該是分布在一條曲線上,無法進行線性擬合。 <img height="60%" width="60%" src="https://imgur.com/i4w60jL.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">θ<sub>2</sub> - θ<sub>1</sub> 關係圖</div> <br /> 接著再試著畫 $\log \theta_2 - \log \theta_1$ 關係圖,圖中的數據點依然不是分布在一條直線上,可以推測兩者的關係應該不是加上次方這麼單純。 <img height="60%" width="60%" src="https://imgur.com/yJ2VLLG.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">log θ<sub>2</sub> - log θ<sub>1</sub> 關係圖</div> <br /> 實際上折射定律為 $$n_1 \sin \theta_1 = n_2 \sin \theta_2 ~\Rightarrow~ \frac{\sin \theta_2}{\sin \theta_1} = \frac{n_1}{n_2}$$ 計算 $\sin \theta_2$、$\sin \theta_1$,再畫出 $\sin \theta_2 - \sin \theta_1$ 關係圖,線性擬合結果為 $斜率 = 0.742805801759476 \pm 0.00561557104745917$ $截距 = 0.00628404135667623 \pm 0.00397080836789323$ $R^2 = 0.999657200936133$ 由於這是光由空氣進到水中的實驗數據,$n_1 = 1$、$n_2 = 4/3$,最接近直線的斜率會很接近0.75,百分誤差$\approx 0.1\%$。 <img height="60%" width="60%" src="https://imgur.com/NMaSb1l.jpg" style="display: block; margin-left: auto; margin-right: auto;"/> <div style="text-align:center">sin θ<sub>2</sub> - sin θ<sub>1</sub> 關係圖</div> <br /> --- ###### tags:`SciDAVis`、`Physics`、`校訂必修`