(71B) Euler-Taylor method for the HP-71B
12-07-2019, 04:36 PM (This post was last modified: 12-11-2019 10:04 PM by Namir.)
Post: #1
 Namir Senior Member Posts: 823 Joined: Dec 2013
(71B) Euler-Taylor method for the HP-71B
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)

HP-71B Listing
==============

Code:
10 REM EULER METHOD WITH 2 DERIVATIVES 20 DEF FNE(X)=EXP(0.5*x^2) 30 DEF FNX(X,Y) = X*y 40 DEF FND(X,Y)=X*FNX(X,Y)+y 50 READ A,B,Y,H 60 DATA 0,1,1,0.01 70 N=INT((B-A)/H+.5) 80 X=A 90 DISP "WAIT PLEASE..." @ WAIT .1 100 FOR I=1 TO N 110 Y = Y + H*FNX(X,Y) + H^2/2*FND(X,Y) 120 X = X + H 130 NEXT I 140 DISP "Y=";Y @ PAUSE 150 Y0 = FNE(B) 160 DISP "Y EXACT=";Y0 @ PAUSE 170 DISP "%ERR=";100*(Y-Y0)/Y0 180 END

Usage
=====

1) With the values in the DATA statements being the ones you want and the definitions of functions FNE, FNX, and FND representing your problem to solve, just press the [RUN] button. The program displays "WAIT PLEASE ..." as it calculates y at x=b.
2) Displays the value of y at x=b. Press [f][Cont] to resume.
3) Displays the exact value of y at x=b. Press [f][Cont] to resume.
4) Displays the % error between the calculated and exact values of y at x=b.

Code Customization
==================

1) Edit the DATA statement to use different values for a, b, y(a), and h.
2) Edit the definitions of functions FNE, FNX, and FND to use a different exact function, a different first derivative, and a different second derivatve, respectively. In the case of FNE, edit the DEF FNE(X) statement to implement the eaxct solutions as a function of variable x only. If that solution is not available use something like:

DEF FNE(X)=1E99

HP-71B Listing 2
================

This version should be faster since the FOR loop calculates the values of the first and second derivative directly and does not resort to calling functions defined in DEF statements.

Code:
10 REM EULER METHOD WITH 2 DERIVATIVES 20 DEF FNE(X)=EXP(0.5*x^2) 30 READ A,B,Y,H 40 DATA 0,1,1,0.01 50 N=INT((B-A)/H+.5) 60 X=A 70 DISP "WAIT PLEASE..." @ WAIT .1 80 FOR I=1 TO N 90 D1 = X*Y 100 D2 = X*D1+Y 110 Y = Y + H*D1 + H^2/2*D2 120 X = X + H 130 NEXT I 140 DISP "Y=";Y @ PAUSE 150 Y0 = FNE(B) 160 DISP "Y EXACT=";Y0 @ PAUSE 170 DISP "%ERR=";100*(Y-Y0)/Y0 180 END
Usage
=====

1) With the values in the DATA statements being the ones you want and the definitions of functions FNE, FNX, and FND representing your problem to solve, just press the [RUN] button. The program displays "WAIT PLEASE ..." as it calculates y at x=b.
2) Displays the value of y at x=b. Press [f][Cont] to resume.
3) Displays the exact value of y at x=b. Press [f][Cont] to resume.
4) Displays the % error between the calculated and exact values of y at x=b.

Code Customization
==================

1) Edit the DATA statement to use different values for a, b, y(a), and h.
2) Edit line 90 to change how the first derivative is calculated and assigned to variable D1.
3) Edit line 100 to change how the first derivative is calculated and assigned to variable D2. You can use variable D1 when the value of teh first derivative is needed.
4) Edit the DEF FNE(X) statement to implement the eaxct solutions as a function of variable x only. If that solution is not available use something like:

DEF FNE(X)=1E99
 « Next Oldest | Next Newest »

 Messages In This Thread (71B) Euler-Taylor method for the HP-71B - Namir - 12-07-2019 04:36 PM RE: (71B) Euler-Taylor method for the HP-71B - Csaba Tizedes - 12-10-2019, 06:02 PM RE: (71B) Euler-Taylor method for the HP-71B - Namir - 12-11-2019, 10:07 PM RE: (71B) Euler-Taylor method for the HP-71B - Albert Chan - 12-13-2019, 02:12 PM RE: (71B) Euler-Taylor method for the HP-71B - Namir - 12-13-2019, 04:10 PM RE: (71B) Euler-Taylor method for the HP-71B - Albert Chan - 12-13-2019, 04:43 PM RE: (71B) Euler-Taylor method for the HP-71B - Csaba Tizedes - 12-14-2019, 08:44 AM RE: (71B) Euler-Taylor method for the HP-71B - Namir - 12-15-2019, 12:23 AM RE: (71B) Euler-Taylor method for the HP-71B - Csaba Tizedes - 12-15-2019, 08:25 AM RE: (71B) Euler-Taylor method for the HP-71B - Albert Chan - 12-15-2019, 08:14 PM RE: (71B) Euler-Taylor method for the HP-71B - Namir - 12-13-2019, 04:07 PM RE: (71B) Euler-Taylor method for the HP-71B - Namir - 12-13-2019, 09:16 PM RE: (71B) Euler-Taylor method for the HP-71B - Namir - 12-14-2019, 03:33 AM RE: (71B) Euler-Taylor method for the HP-71B - Namir - 12-16-2019, 11:23 PM

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