470 likes | 656 Views
最小二平方法 與 方程式求解. 張基昇製作. 目錄. 最小二平方法 方程式求解 方程式範例: van der Waals EOS Analysis of the problem 嘗試錯誤法 B isection method Secant method ; False position method Newton’s method ; Muller’s method 疊代法 : Fixed-point iteration. 最小二平方法. 實驗量測取得數據. 最小二平方法. 數據處理 數據點作圖 選擇三個數學模 式來吻合數據 , 何者最適當?.
E N D
最小二平方法與方程式求解 張基昇製作
目錄 • 最小二平方法 • 方程式求解 • 方程式範例:van der Waals EOS • Analysis of the problem • 嘗試錯誤法 • Bisection method • Secant method ; False position method • Newton’s method ; Muller’s method • 疊代法:Fixed-point iteration
最小二平方法 • 實驗量測取得數據
最小二平方法 • 數據處理 • 數據點作圖 • 選擇三個數學模式來吻合數據,何者最適當?
最小二平方法 • 最適當數學模式的觀念: • 該模式計算值與實驗值間之誤差較小 • 取誤差的平方和最小為判別標的
最小二平方法 • 在數學上極值的取得 • 對函數作變數之一次偏導數等於 0 時之變數值
最小二平方法 • 移項整理得兩個方程式的方程組 • 兩個未知變數 a 與 b,有兩個方程式,系統自由度為0
最小二平方法 • 第(1)式與第(2)式除以數據點數 N,可以得到如下平均值表示為(3) 、(4)
最小二平方法 • 第(1)式減去第(4)式乘以xi值,將消去 b 變數,取得a (5)式(或值)
最小二平方法 • 將 a (5)式(或值)帶入第(4)式,即可求取 b (6)式(或值)
Fit1.for 程式解說 • 宣告因次與宣告實數 • (426) dimension x(100),y(100) • real*4 interp,meanx,meany • 開啟檔案 • open(1,file='fit1d.dat', status='old') • open(6,file='fit1.prn', status='new')
Fit1.for 程式解說 • 讀入數據組數 • (430) read(1,*)n • 用迴圈讀入數據 • (431) do 1 i=1,n read(1,*)x(i),y(i) 1 continue
Fit1.for 程式解說 • 宣告各個計算變數為 0.0 的值 • (434) sumx = 0.0 • sumy = 0.0 • sumx2 = 0.0 • sumy2 = 0.0 • sumxy = 0.0 • meanx = 0.0 • meany = 0.0
Fit1.for 程式解說 • 利用迴圈計算各個總和數值 • (441) do 2 i = 1, n • sumx = sumx + x(i) • sumy = sumy + y(i) • sumx2 = sumx2 + x(i)*x(i) • sumy2 = sumy2 + y(i)*y(i) • sumxy = sumxy + x(i)*y(i) • 2 continue enddo
Fit1.for 程式解說 • 計算平均值、斜率與截距 • (449) meanx = sumx / n • meany = sumy / n • (a值) slope = (sumxy - sumx*meany) /(sumx2 - sumx*meanx) • (b值) interp = meany - slope*meanx • coef = (…) 計算統計上的標準偏差值
Fit1.for 程式解說 • 依指定格式列印結果 • (455) write(6,1000) slope,interp,coef • 1000 format( …) • stop • end
最小二平方法 • ㄧㄝˋ ! • 完成最小二平方法之數據處理,取得系統之最適當數學模式的參數 a 與 b。
van der Waals equation of state • 立方型體積狀態方程式 • ㄧ、 • 二、 • 三、
Cubic EOS • 立方型體積狀態方程式 • 臨界常數應用於方程式物質參數的求取
van der Waals equation of state • vdW 狀態方程式的物質參數 • ㄧ、 , ,. • 二、 , .
Cubic Equation of State • 體積的一元三次方程式 • 在一指定溫度與指定壓力之下,可以解得三個體積的根。
Cubic EOS • 立方型體積狀態方程式 • 蒸氣相莫耳體積的求取計算式
Cubic EOS • 立方型體積狀態方程式 • 液相莫耳體積的求取計算式
題解分析 • Degree of Freedom of problems • 自由度:數學的與熱力學的觀點 • 依 Gibbs 相律計算,自由度為 2,指定 T與 P • ,V 為所剩唯一變數;一個未知變數,一個方程式,自由度F = 0
(一)嘗試錯誤法求解 • 嘗試錯誤法 • 給一個解的起猜值 V ,計算函數值是否為 0 ,若函數值小於容忍誤差() ,即可視為計算收斂,取得函數的解。 • 否則,繼續嘗試可能的解,ㄧ直到得到適當解為止。
Bisection method • 解題的邏輯觀念示意圖
Bisection method • Step A • Read: T、P、Tc、Pc,calculate a and b。 • Set V0 and V1 ,calculate f0 and f1 ,have to satisfy [ f0*f1 < 0 ] • IF ( | f0 | < .or. | f1 |< ) THEN Stop。
Bisection method • Step B • Repeat • Calculate V2 and f2 • IF ( f2 * f0 > 0 ) THEN Set V0 = V2 and f0 = f2ELSE Set V1 = V2 and f1 = f2ENDIF • Until | f2 |< Then Stop。
Bisection method • Formula by Bisection method
Secant method • 解題的邏輯觀念示意圖
Secant method • Step A • Read: T、P、Tc、Pc,calculate a and b。 • Set V0 and V1 ,calculate f0 and f1 • IF ( | f0 | < .or. | f1 |< ) THEN Stop。 • IF ( | f1 | > | f0 | ) THENSwap V0 withV1 andf0 with f1
Secant method • Step B • Repeat • Calculate V2 and f2 • Set V0 = V1 and f0 = f1 Set V1 = V2 and f1 = f2 • Until | f2 |< Then Stop。
Secant method • Formula by Secant method
False position method • 解題的邏輯觀念示意圖
False position method • Step A • Read: T、P、Tc、Pc,calculate a and b。 • Set V0 and V1 ,calculate f0 and f1 , have to satisfy [ f0*f1 > 0 ] • IF ( | f0 | < .or. | f1 |< ) THEN Stop。
False position method • Step B • Repeat • Calculate V2 and f2 • IF ( f2 * f0 > 0 ) THEN Set V0 = V2 and f0 = f2ELSE Set V1 = V2 and f1 = f2ENDIF • Until | f2 |< Then Stop。
False position method • Formula by False position method
Newton’s methods • 解題的邏輯觀念示意圖
Newton’s methods • Step A • Read: T、P、Tc、Pc,calculate a and b。 • Set Vi,calculate fi and fi’, • IF ( | fi | < 1.or. | fi’|< 2 ) THEN Stop。
Newton’s methods • Step B • Repeat • Calculate Vi+1 and fi+1 and fi+1’, • Until ( | fi | < 1.or. | fi’|< 2 )
Newton’s methods • Formula by Newton’s methods
(二)疊代法求解 • 疊代計算的邏輯觀念 • 將體積狀態方程式整理成為體積之自我函數關係式 • 疊代計算收斂之判別式
疊代法求解 • vdW 狀態方程式範例 • ㄧ、 • 二、 • 三、 • 四、
您可已曉得! • 劇情如何發展! • 敬請期待!