Post Reply 
(41C) Euler-Taylor method (updated)
12-07-2019, 04:21 PM (This post was last modified: 12-19-2019 02:00 PM by Namir.)
Post: #1
(41C) Euler-Taylor method (updated)
Euler-Taylor method
===================

To integrate f'(x,y) from x=a to x=b, give y(a), we use an extended version of the Euler method that includes the first AND second derivatives. Since we know f'(x,y) we can derive f''(x,y) and use the following formula:

y = y + h*f'(x,y) + h^2/2*f''(x,y)

Memory Map
==========
Code:

R00 = a,x
R01 = b
R02 = h
R03 = y
R04 = nsteps
R05 = used

LABELS
======

A - Main routine.
B - calculate first derivative f'(x,y).
C - calculate second derivative f''(x,y).
E - calculate exact f(x,y) (used for results comparison). If the exact solution is not known, then just have the label just return a value like 0 or insert "N/A" into register X.

Listing
=======

Code:
1  LBL "EULTLR"
2  LBL A
3  A/^B?
4  PROMPT
5  STO 01
6  RDN
7  STO 00
8  Y/^H?
9  PROMPT
10  STO 02
11  RDN
12  stO 03
13  RCL 01
14  RCL 00
15  -
16  RCL 02
17  /
18  0.5
19  +
20  INT  
21  0.001
22  +
23  STO 04  # calclate and store nsteps
24  LBL 00
25  XEQ B   # calculate f'(x,y)
26  RCL 02
27  *
28  STO 05
29  XEQ C   # calculate f''(x,y)
30  RCL 02
31  STO+00
32  X^2
33  *
34  2
35  /
36  STO+ 05
37  RCL 05
38  STO+ 03
39  VIEW 03
40  DSE 04
41  GTO 00
42  CLD
43  RCL 01
44  XEQ E
45  RCL 03  # recall calculated y at x=b
46  RTN
47  LBL B  # calculate f'(x,y) = y * x
48  RCL 03
49  RCL 00
50  *
51  RTN
52  LBL C # calculate f''(x,y) = x*dy/dx + y
53  XEQ B
54  RCL 00
55  *
56  RCL 03
57  +
58  RTN
59  LBL E  # exact f(x,y) = g(x) = exp(0.5*x^2)
60  X^2
61  2
62  /
63  EXP
64  RTN

Usage
=====

1. Run the program using XEQ "ELRTLR" or pressing key [A].
2. Program prompts "A/^B?". Key in the value for a, press [ENTER], key in the value for b, and then press [R/S] key.
3. Program prompts "Y/^H?". Key in the value for y(a), press [ENTER], key in the value for increment h, and then press [R/S] key.
4) Program displays intermediate values of the integrated y. The program stops with the calculated value of y at x=b.
5) Press [X<>Y] to view the exact value of y at x=b.

You calculate the value for y at any value of x by entering the value of x and the pressing the [E] key.
Find all posts by this user
Quote this message in a reply
12-15-2019, 01:33 AM (This post was last modified: 12-15-2019 01:35 AM by Namir.)
Post: #2
RE: (41C) Euler-Taylor method
The next version of the Euler-Taylor program uses the approximation for the second derivative that Albert Chan came up with (click here). Thus we can eliminate LBL C and its code. The program interacts with the user like in the first version:

Code:

01    LBL "EULTLR"
02     LBL A
03    "A/^B?"
04     PROMPT
05     STO 01
06    RDN
07    STO 00
08    "Y/^H?"
09    PROMPT
10    STO 02
11    RDN
12    StO 03
13     RCL 01
14    RCL 00
15    -
16    RCL 02
17    /
18    0.5
19     +
20    INT  
21     0.001
22    +
23    STO 04  # calclate and store nsteps
24    LBL 00
25    XEQ B   # calculate f'(x,y)
26    STO 05 # Calculate D1=f'(x,y)
27    RCL 02
28    STO+ 00 # x = x +h
29    *
30    STO+ 03 # y = y + h*D1
31    XEQ B   # calculate f'(x,y)
32    RCL 05
33    -
34    RCL 02
35    *
36    2
37    /
38    STO+ 03 # y = y + h/2*(f'(x,y)-D1)
39    VIEW 03
40     DSE 04
41    GTO 00
42    CLD
43    RCL 01
44    XEQ E
45    RCL 03  # recall calculated y at x=b
46    RTN
47    LBL B  # calculate f'(x,y) = y * x
48    RCL 03
49    RCL 00
50    *
51    RTN
52    LBL E  # exact f(x,y) = g(x) = exp(0.5*x^2)
53    X^2
54    2
55    /
56    EXP
57    RTN
Find all posts by this user
Quote this message in a reply
12-18-2019, 08:12 PM
Post: #3
RE: (41C) Euler-Taylor method
A third version of the program uses approximations for the second and third function derivatives, yielding better accuracy.

Memory Map
==========

Code:
R00 = a,x
R01 = b
R02 = h
R03 = y
R04 = nsteps
R05 = D1
R06 = D2
R07 = D3

LABELS
======

Code:
A - Main routine.
B - calculate first derivative f'(x,y).
E - calculate exact f(x,y) (used for results comparison). If the exact solution is not known, then just have the label just return a value like 0 or insert "N/A" into register X.

Listing
=======

Code:
1    LBL "EULTL3"
2    LBL A
3    A/^B?
4    PROMPT
5    STO 01
6    RDN
7    STO 00
8    Y/^H?
9    PROMPT
10    STO 02
11    RDN
12    StO 03
13    RCL 01
14    RCL 00
15    -
16    RCL 02
17    /
18    0.5
19    +
20    INT  
21    0.001
22    +
23    STO 04  # calclate 
24    SF 00   # set flag 
25    LBL 00
26    XEQ B   # calculate
27    STO 05 # Calculate 
28    RCL 02
29    STO+ 00 # x = x +h
30    *
31    STO+ 03 # y = y + h
32    XEQ B   # calculate
33    RCL 05
34    -
35    RCL 02
36    *
37    2
38    /
39    STO 06
40    STO+ 03 # y = y + D
41    FS?C 00
42    GTO 01
43    RCL 06
44    RCL 07
45    -
46    3
47    /
48    STO+ 03  # y =y + (
49    LBL 01
50    VIEW 03
51    RCL 06
52    STO 07  # D3 = D2
53    DSE 04
54    GTO 00
55    CLD
56    RCL 01
57    XEQ E
58    RCL 03  # recall ca
59    RTN
60    LBL B  # calculate 
61    RCL 03
62    RCL 00
63    *
64    RTN
65    LBL E  # exact f(x,
66    X^2
67    2
68    /
69    EXP
70    RTN
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)