21
inc Heun Method The simplest example of a predictor corrector method A “marching” method for obtaining ordered pairs starting with an initial value set

Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Heun Method

The simplest example of a predictor corrector method

A “marching” method for obtaining ordered pairs starting with an initial value set

Page 2: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Heun Example

The application of the Heun method using a know form for the differential equation,

(2)

Notation Examples:

2 f(z) = z +4z + 12z -75 3

This function could be labeled f(z) since there was no F(z) term in the expression. (1) f(z, F(z) ) = z +4z + 12z -75 2 3

Page 3: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Heun Example

This function can not be labeled f(z) since there is a F(z) term in the expression.

(2)

Notation Examples:

2 f(z) = z +4z + 12z -75 3

This function could be labeled f(z) since there was no F(z) term in the expression. (1) f(z, F(z) ) = z +4z + 12z -75 2 3

0.8x f(x, y) = 4 e - 0.5 F(x)

Additional Required Information initial ordered pair, (0,2)

The application of the Heun method using a know form for the differential equation,

Page 4: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?) desired ordered pair (0 , 2) Initial ordered pair Two correction Heun calculation

For predictor/corrector marching methods it is a two step process for each corrected “answer”

The objective is to obtain the other value in the ordered pair (1,?). After that value is obtained at an approximation level that satisfies the uncertainty of measurement system you “march” on to obtain the two values in the next ordered pair in the sequence.

= 2 + (∆ x) f(x,F(x))

F(0) = 2

dx dy

X= 0 + 2∆x F(2) = F(1) + (∆ x)

= 2 + (∆ x) f(x,F(x)) dx dy

X= 0 F(1) = 2 + (∆ x)

= 2 + (∆ x) f(x,F(x)) dx dy

X= 0 + 1∆x F(2) = F(1) + (∆ x)

X= 0

X= 0 + 1∆x

X= 0 + 2∆x

Page 5: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?) desired ordered pair (0 , 2) Initial ordered pair Two correction Heun calculation

Two step process for each corrected “answer”

Step #1: Use the Euler to get a prediction of the “answer”. solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

(1 , ?)

Page 6: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x

Two correction Heun calculation

Two step process for each corrected “answer”

Step #1: Use the Euler to get a prediction of the “answer”. solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

F(1) = 2 + f(0,2) (1) = ? ] [ (1 , ?)

(1 , ?) desired ordered pair (0 , 2) Initial ordered pair

f ( 0, 2 ) = 4 e - 0.5 (2) = 3 [ ] 0

Page 7: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x

Two correction Heun calculation

Two step process for each corrected “answer”

When x = 1 the F(x) value is suppose to equal 5.

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

F(1) = 2 + f(0,2) (1) = ? ] [ (1 , ?)

F (1) = 2 + 3(1) = 5

value for F(1) obtained using Euler ( the predicted value)

equation based on initial Euler method results.)

(A predicted solution to differential 0

(1 , ?) desired ordered pair

(1 , 5 ) predicted ordered pair

(0 , 2) Initial ordered pair

Step #1: Use the Euler to get a prediction of the “answer”.

f ( 0, 2 ) = 4 e - 0.5 (2) = 3 [ ] 0

(1, 5 )

Page 8: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x

Two correction Heun calculation

Two step process for each corrected “answer”

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

F(1) = 2 + f(0,2) (1) = ? ] [ (1 , ?)

(1, 5 )

F (1) = 2 + 3(1) = 5

value for F(1) obtained using Euler ( the predicted value)

equation based on initial Euler method results.)

(A predicted solution to differential 0

(1 , ?) desired ordered pair

(1 , 5 ) predicted ordered pair

(0 , 2) Initial ordered pair

Step #1: Use the Euler to get a prediction of the “answer”.

f ( 0, 2 ) = 4 e - 0.5 (2) = 3 [ ] 0

If this predicted value isn’t good enough, it is time to move on to the correction step!

When x = 1 the F(x) value is suppose to equal 5.

Page 9: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example:

f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x

Two correction Heun calculation

Two step process for each corrected “answer”

Step #2: the correction to the Euler prediction of the “answer”.

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

F(1) = 2 + f(0,2) (1) = ?

f ( 0, 2 ) = 4 e - 0.5 (2) = 3

] [

[ ] 0

(1 , ?)

f (1, 5) = 4 e - (0.5) 5 = 6.402 0.8(1) P ] [

(A predicted solution to differential equation when x = 1

F (1) = 2 + 3(1) = 5 0

desired ordered pair

predicted ordered pair

Initial ordered pair

Step #1: Use the Euler to get a prediction of the “answer”.

(1 , ?) (1 , 5 )

(0 , 2)

f (1, 5) = 4 e - (0.5) F(1) = ? 0.8(1) P ] [

(1, 5 )

(1, 5 )

f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x

Page 10: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?)

(1 , ? )

desired ordered pair

predicted ordered pair

(0 , 2) Initial ordered pair Two correction Heun calculation

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

Heun first correction to solution value, F(1).

F (x) = c 1

Step #2: the correction to the Euler prediction of the “answer”.

f (1, 5) = 4 e - (0.5) 5 = 6.402 0.8(1) P ] [

f (1, 5) = 4 e - (0.5) F(1) = ? 0.8(1) P ] [

(1, 5 )

First correction (1 , 5 )

Page 11: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?)

(1 , ? )

desired ordered pair

First correction

predicted ordered pair

(0 , 2) Initial ordered pair Two correction Heun calculation

solution value using Euler

{ } (1) ? F (x) = 2 + c 1

Step #2: the correction to the Euler prediction of the “answer”.

f (1, 5) = 4 e - (0.5) 5 = 6.402 0.8(1) P ] [

f (1, 5) = 4 e - (0.5) F(1) = ? 0.8(1) P ] [

(1, 5 )

Heun first correction to solution value, F(1).

(1 , 5 )

current value of F(x)

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

Page 12: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?)

(1 , ? )

desired ordered pair

predicted ordered pair

(0 , 2) Initial ordered pair

F (x) = 2 + c 1

Two correction Heun calculation

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

? { } (1) = 2 [4 e - 0.5(2)] 0.8(0) [4 e - 0.5(5)] 0.8(1) +

First correction

Step #2: the correction to the Euler prediction of the “answer”.

f (1, 5) = 4 e - (0.5) 5 = 6.402 0.8(1) P ] [

f (1, 5) = 4 e - (0.5) F(1) = ? 0.8(1) P ] [

(1, 5 )

Heun first correction to solution value, F(1).

(1 , 5 )

current value of F(x)

Page 13: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?)

(1 , ? )

desired ordered pair

predicted ordered pair

(0 , 2) Initial ordered pair

2 { } F (x) = 2 + [ ] (1) = 2 + { } (1)= ? c

1 3 + 6.402

Two correction Heun calculation

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [ First correction

Step #2: the correction to the Euler prediction.

f (1, 5) = 4 e - (0.5) 5 = 6.402 0.8(1) P ] [

f (1, 5) = 4 e - (0.5) F(1) = ? 0.8(1) P ] [

(1, 5 )

Heun first correction to solution value, F(1).

(1 , 5 )

current value of F(x)

Page 14: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?)

(1 , 6.702)

desired ordered pair

(1 , ? ) Second correction

(1 , 5 ) predicted ordered pair

(0 , 2) Initial ordered pair

f( 1, 6.702) =[ 4 e - 0.5 (6.702)] 0.8(1) 2

{ } F (x) = 2 + [ ] (1) = 2 + {4.702} (1)= 6.702 3 + 6.402

Two correction Heun calculation

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

Step #2: the correction to the Euler prediction.

f (1, 5) = 4 e - (0.5) 5 = 6.402 0.8(1) P ] [

f (1, 5) = 4 e - (0.5) F(1) = ? 0.8(1) P ] [

(1, 6.702 )

Heun first correction to solution value, F(1).

c 1

(1, 5 )

When x = 1 the F(x) value is now suppose to equal 6.702.

First correction

Page 15: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?)

(1 , 6.702)

desired ordered pair

(1 , ? ) Second correction

(1 , 5 ) predicted ordered pair

(0 , 2) Initial ordered pair

f( 1, 6.702) =[ 4 e - 0.5 (6.702)] 0.8(1) 2

{ } F (x) = 2 + [ ] (1) = 2 + {4.702} (1)= 6.702 3 + 6.402

Two correction Heun calculation

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

Step #2: the correction to the Euler prediction.

f (1, 5) = 4 e - (0.5) 5 = 6.402 0.8(1) P ] [

f (1, 5) = 4 e - (0.5) F(1) = ? 0.8(1) P ] [

(1, 6.702 )

Heun first correction to solution value, F(1).

c 1

(1, 5 )

If this corrected value still isn’t good enough, it is time to move on to a second correction step!!

When x = 1 the F(x) value is now suppose to equal 6.702.

First correction

Page 16: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?)

(1 , 6.702)

desired ordered pair

(1 , ? ) Second correction

(1 , 5 ) predicted ordered pair

(0 , 2) Initial ordered pair

f( 1, 6.702) =[ 4 e - 0.5 (6.702)] 0.8(1) 2

{ } F (x) = 2 + [ ] (1) = 2 + {4.702} (1)= 6.702 3 + 6.402

Two correction Heun calculation

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

(1, 6.702 )

Heun first correction to solution value, F(1).

c 1

(1, 5 ) Original predicted value of F(x) =5 when x =1

Heun second correction to the predicted value of F(1)

? { } (1) 2

F (x) = 2 + c 2

F (x) = 2 + c 2

First correction

continue to use the current value of F(x)

Page 17: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?)

(1 , 6.702)

desired ordered pair

(1 , ? ) Second correction

(1 , 5 ) predicted ordered pair

(0 , 2) Initial ordered pair

f( 1, 6.702) =[ 4 e - 0.5 (6.702)] 0.8(1) 2

{ } F (x) = 2 + [ ] (1) = 2 + {4.702} (1)= 6.702 3 + 6.402

Two correction Heun calculation

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

(1, 6.702 )

Heun first correction to solution value, F(1).

c 1

(1, 5 ) Original predicted value of F(x) =5 when x =1

Heun second correction to the predicted value of F(1)

? { } (1) 2

F (x) = 2 + c 2

F (x) = 2 + c 2 { }

2 [4 e - 0.5(2)] 0.8(0) [4 e - 0.5(6.702] 0.8(1) + (1) = ?

First correction

Page 18: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , ?)

(1 , 6.702)

desired ordered pair

(1 , 6.382 ) Second correction

(1 , 5 ) predicted ordered pair

(0 , 2) Initial ordered pair

f( 1, 6.702) =[ 4 e - 0.5 (6.702)] 0.8(1) 2

{ } F (x) = 2 + [ ] (1) = 2 + {4.702} (1)= 6.702 3 + 6.402

Two correction Heun calculation

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

(1, 6.382 )

Heun first correction to solution value, F(1).

c 1

(1, 5 ) Original predicted value of F(x) =5 when x =1

Heun second correction to the predicted value of F(1)

? { } (1) 2

F (x) = 2 + c 2

F (x) = 2 + c 2 { }

2 [4 e - 0.5(2)] 0.8(0) [4 e - 0.5(6.702] 0.8(1) + (1) = 6.382

(1, 6.702 )

First correction

Page 19: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

Example: f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x (1 , 6382) desired ordered pair (0 , 2) Initial ordered pair

f( 1, 6.702) =[ 4 e - 0.5 (6.702)] 0.8(1) 2

{ } F (x) = 2 + [ ] (1) = 2 + {4.702} (1)= 6.702 3 + 6.402

Two correction Heun calculation

solution value using Euler

current value of F(x) 0 F(x) = F(x ) + f(x ,F(x ) 0 0 ](h) [

(1, 6.382 )

Heun first correction to solution value, F(1).

c 1

(1, 5 ) Original predicted value of F(x) =5 when x =1

Heun second correction to the predicted value of F(1)

? { } (1) 2

F (x) = 2 + c 2

F (x) = 2 + c 2 { }

2 [4 e - 0.5(2)] 0.8(0) [4 e - 0.5(6.702] 0.8(1) + (1) = 6.382

(1, 6.702 )

When x = 1 the F(x) value is now really suppose to equal 6.382

Page 20: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

f(x, F(x) ) = 4 e - 0.5 F(x) 0.8x

(1 , 6.195)

(1 , 6.702)

correct ordered pair

1st correction

(1 , 6.382) 2nd correction

(1 , 5 ) predicted ordered pair

(0 , 2) Initial ordered pair

The analytical solution of this example differential equation gives the correct ordered pair as (1, 6.195 ).

Plot the relative error.

2st corrected value

Predicted value

1st corrected value

100%

0%

Correct value

rela

tive

erro

r

Two correction Heun calculation

Write a MATLAB routine that will do this two correction numerical method.

Have the routine also calculate and plot the relative errors as well.

Have the routine check the results provided to the left.

Page 21: Heun Method - University of South Floridanatasha.eng.usf.edu/.../experiments/cstr/2_heun_2_correction_example.pdf · inc Heun Method . The simplest example of a predictor corrector

inc

End of Presentation

Two correction Heun calculation