最小二平方法 與 方程式求解

Post on 03-Jan-2016

100 views 1 download

description

最小二平方法 與 方程式求解. 張基昇製作. 目錄. 最小二平方法 方程式求解 方程式範例: 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. 最小二平方法. 實驗量測取得數據. 最小二平方法. 數據處理 數據點作圖 選擇三個數學模 式來吻合數據 , 何者最適當?. - PowerPoint PPT Presentation

Transcript of 最小二平方法 與 方程式求解

11

最小二平方法與

方程式求解

張基昇製作

22

目錄

最小二平方法 方程式求解

方程式範例: van der Waals EOS Analysis of the problem 嘗試錯誤法

• Bisection method• Secant method ; False position method • Newton’s method ; Muller’s method

疊代法: Fixed-point iteration

33

最小二平方法

實驗量測取得數據實驗量測取得數據

N 11 22 33 44 55 66

xi 0.050.05 0.110.11 0.150.15 0.310.31 0.460.46 0.520.52

yi 0.9560.956 0.8900.890 0.8320.832 0.7170.717 0.5710.571 0.5390.539

N 77 88 99 1010 1111

xi 0.700.70 0.740.74 0.820.82 0.980.98 1.171.17

yi 0.3780.378 0.3700.370 0.3060.306 0.2420.242 0.1040.104

44

數據處理數據處理 數據點作圖數據點作圖 選擇三個數學模選擇三個數學模式來吻合數據式來吻合數據,,何者最適當?何者最適當?

最小二平方法

baxy i

baxy

55

最小二平方法

最適當數學模式的觀念最適當數學模式的觀念: : 該模式計算值與實驗值間之誤差較小該模式計算值與實驗值間之誤差較小

取誤差的平方和最小為判別標的取誤差的平方和最小為判別標的

N

iii baxyE

1

22 )(

)( yyE i

)( baxyE ii

66

最小二平方法

在數學上極值的取得 對函數作變數之一次偏導數等於 0 時之變數值

0))((2

)(

1

2

i

N

iii xbaxy

a

E

0)1)((2

)(

1

2

N

iii baxy

b

E

N

iii baxyE

1

22 )(

77

最小二平方法

移項整理得兩個方程式的方程組 兩個未知變數 a 與 b ,有兩個方程式,系統自由度為 0

(1) --- 111

2

N

iii

N

ii

N

ii yxxbxa

(2) --- 11

N

ii

N

ii yNbxa

88

最小二平方法

第 (1) 式與第 (2) 式除以數據點數 N ,可以得到如下平均值表示為 (3) 、(4)

(4)--- ybxa

(3) --- //11

2 NyxxbNxaN

iii

N

ii

99

最小二平方法

第 (1) 式減去第 (4) 式乘以 xi 值,將消去 b 變數,取得 a (5) 式 ( 或值 )

(5) ---

11

2

11

xxx

yxyx

aN

ii

N

ii

N

ii

N

iii

1010

最小二平方法

將 a (5) 式 ( 或值 ) 帶入第 (4) 式,即可求取 b (6) 式 ( 或值 )

(6) --- xayb

1111

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')

1212

Fit1.for 程式解說

讀入數據組數 (430) read(1,*)n

用迴圈讀入數據 (431) do 1 i=1,n

read(1,*)x(i),y(i) 1 continue

1313

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

1414

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

1515

Fit1.for 程式解說

計算平均值、斜率與截距 (449) meanx = sumx / n meany = sumy / n (a 值 ) slope = (sumxy - sumx*meany)

/(sumx2 - sumx*meanx) (b 值 ) interp = meany - slope*meanx coef = (…)

計算統計上的標準偏差值

1616

Fit1.for 程式解說

依指定格式列印結果 (455) write(6,1000) slope,interp,coef 1000 format( …) stop end

1717

最小二平方法

ㄧㄝˋ !

完成最小二平方法之數據處理,取得系統之最適當數學模式的參數 a 與 b 。

1818

van der Waals equation of state

立方型體積狀態方程式

ㄧ、

二、

三、

RTbV V

aP

2

2V

a

bV

RTP

0P

abV

P

aV

P

RTb-V 23

1919

立方型體積狀態方程式 臨界常數應用於方程式物質參數的求取

Cubic EOSCubic EOS

2020

van der Waals equation of state

vdW 狀態方程式的物質參數 ㄧ、 ,

,

.

二、 , .

C

2C

2

P

TR

64

27a

C

C

P

RT

8

1b

C

CC P

RTb3V

C

2C P

a3V

C

3C P

abV

2121

Phase Diagram

2222

Phase Diagram

2323

Cubic Equation of State

體積的一元三次方程式 在一指定溫度與指定壓力之下,可以解得三個體積的根。

2424

2525

立方型體積狀態方程式 蒸氣相莫耳體積的求取計算式

Cubic EOSCubic EOS

2626

立方型體積狀態方程式 液相莫耳體積的求取計算式

Cubic EOSCubic EOS

2727

題解分析題解分析

Degree of Freedom of problems 自由度:數學的與熱力學的觀點

依 Gibbs 相律計算,自由度為 2 ,指定 T 與 P

, V 為所剩唯一變數;一個未知變數,一個方程式,自由度 F = 0

0),,( VTPf

2828

( 一 ) 嘗試錯誤法求解

嘗試錯誤法 給一個解的起猜值 V ,計算函數值是否為 0 ,若函數值小於容忍誤差 () ,即可視為計算收斂,取得函數的解。

否則,繼續嘗試可能的解,ㄧ直到得到適當解為止。

0),,( VTPf

2929

Bisection method

解題的邏輯觀念示意圖

)( 0xf

)( 3xf

)( 1xf

)( 2xf

0x 2x 4x

3x 1x

)(xf

x

3030

Bisection method

Step AStep A Read: TRead: T 、、 PP 、、 TTcc 、、 PPcc ,, calculate a calculate a

and band b 。。 Set VSet V00 and V and V1 1 ,, calculate fcalculate f0 0 and fand f1 1 ,,

have to satisfy [ fhave to satisfy [ f00 ** ff11 < 0 ] < 0 ] IF ( | fIF ( | f0 0 | <| < .or. | f .or. | f1 1 || < < ) THEN Stop ) THEN Stop 。。

3131

Bisection method

Step BStep B RepeatRepeat Calculate VCalculate V2 2 and fand f22 IF ( fIF ( f2 2 * * ff00 > 0 ) THEN > 0 ) THEN

Set V Set V0 0 = V= V2 2 and fand f0 0 = f= f22 ELSE ELSE Set V Set V1 1 = V= V2 2 and fand f1 1 = f= f22 ENDIFENDIF

Until | fUntil | f2 2 || < < Then Stop Then Stop 。。

3232

Bisection method

Formula by Bisection method

2

)( 102

VVV

3333

Secant method

解題的邏輯觀念示意圖

)( 0xf

)( 1xf

)( 2xf

0x2x

1x

)(xf

x

3434

Secant method

Step AStep A Read: TRead: T 、、 PP 、、 TTcc 、、 PPcc ,, calculate a calculate a

and band b 。。 Set VSet V00 and V and V1 1 ,, calculate fcalculate f0 0 and fand f1 1

IF ( | fIF ( | f0 0 | < | < .or. | f .or. | f1 1 || < < ) THEN Stop ) THEN Stop 。。 IF ( | fIF ( | f1 1 | > | f| > | f0 0 | ) THEN| ) THEN

Swap VSwap V00 withV withV1 1 andand ff0 0 with fwith f1 1

3535

Secant method

Step BStep B RepeatRepeat Calculate VCalculate V2 2 and fand f22 Set VSet V0 0 = V= V1 1 and fand f0 0 = f= f1 1

Set VSet V1 1 = V= V2 2 and fand f1 1 = f= f22 Until | fUntil | f2 2 || < < Then Stop Then Stop 。。

3636

Secant method

Formula by Secant method

)(

)(

10

10112 ff

VVfVV

0 that assume ; )(

)(2

10

10

12

12

fff

VV

ff

VV

3737

False position method

解題的邏輯觀念示意圖

)( 1xf

1x0x

)( 0xf

rxRoot

2x1x

3838

False position method

Step AStep A Read: TRead: T 、、 PP 、、 TTcc 、、 PPcc ,, calculate a calculate a

and band b 。。 Set VSet V00 and V and V1 1 ,, calculate fcalculate f0 0 and fand f1 1 ,,

have to satisfy [ f have to satisfy [ f00 ** ff11 > 0 ] > 0 ] IF ( | fIF ( | f0 0 | <| < .or. | f .or. | f1 1 || < < ) THEN Stop ) THEN Stop 。。

3939

False position method

Step BStep B RepeatRepeat Calculate VCalculate V2 2 and fand f22 IF ( fIF ( f2 2 * * ff00 > 0 ) THEN > 0 ) THEN

Set V Set V0 0 = V= V2 2 and fand f0 0 = f= f22 ELSE ELSE Set V Set V1 1 = V= V2 2 and fand f1 1 = f= f22 ENDIFENDIF

Until | fUntil | f2 2 || < < Then Stop Then Stop 。。

4040

False position method

Formula by False position method

)(

)(

10

10112 ff

VVfVV

0 that assume ; )(

)(2

10

10

12

12

fff

VV

ff

VV

4141

Newton’s methods

解題的邏輯觀念示意圖

)( 0xf

)( 1xf)(' 0xf 0x

1x

)(xf

x

)(' 1xf

4242

Newton’s methods

Step AStep A Read: TRead: T 、、 PP 、、 TTcc 、、 PPcc ,, calculate a calculate a

and band b 。。 Set VSet Vii ,, calculate fcalculate fi i and fand fii’,’, IF ( | fIF ( | fi i | < | < 11 .or. | f .or. | fii’’ || < < 22 ) THEN Sto ) THEN Sto

pp 。。

4343

Newton’s methods

Step BStep B RepeatRepeat Calculate VCalculate Vi+1 i+1 and fand fi+1 i+1 and fand fi+1i+1’,’, Until ( | fUntil ( | fi i | < | < 11 .or. | f .or. | fii’’ || < < 22 ) )

4444

Newton’s methods

Formula by Newton’s methods

'1i

iii f

fVV

1|)('

0 that assume ; '

1

11

2112

12

VdV

dfVf

ffff

VV

4545

( 二 )疊代法求解

疊代計算的邏輯觀念 將體積狀態方程式整理成為體積之自我函數關係式

疊代計算收斂之判別式

0),,( VTPf

),,(1 nn VTPfV

nn VV 1

4646

疊代法求解

vdW 狀態方程式範例 ㄧ、

二、

三、

四、

2V P

b)-(V a

P

RTbV

23 V

P

RTb-V

a

P-bV

P

RTb /

P

abV

P

aVV 32

P

abV

P

aV

P

RTbV 23

4747

您可已曉得!

劇情如何發展!劇情如何發展!

敬請期待!敬請期待!