Post Reply 
Compact Simpson's Rule
12-13-2015, 02:06 AM (This post was last modified: 12-13-2015 02:12 AM by Namir.)
Post: #1
Compact Simpson's Rule
This listing calculates the integral for f(X)=1/X (see label E) using Simpson's rule. The code is based on the compact pseudo-code that I posted in a thread in the General area.

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

R00 = Sum
R01 = A
R02 = B
R03 = h
R04 = 2 or 4
R05 = N

Listing
=======

01 LBL "SIMPS"
02 LBL A
03 "A/^B?"
04 PROMPT
05 STO 02 # store upper limit for integral
06 X<>Y
06 STO 01 # store lower limit for integral
08 "N?"
09 PROMPT
10 STO 05 # store number of divisions. Must be even.
11 RCL 02
12 RCL 01
13 -
14 X<>Y
15 /
16 STO 03 # store h
17 RCL 01
18 XEQ E # Calculate f(A)
19 STO 00 # sum = f(A)
20 RCL 02
21 XEQ E # Calculate f(B)
22 ST- 00 # sum = f(A) - f(B) ... this is part of a math trick
23 RCL 03
24 ST+ 01 # A = A + h
25 4
26 STO 04
27 LBL 00 # start loop
28 RCL 03
29 XEQ E # Calculate f(A)
30 RCL 04
31 *         # multiply by 4 or 2
32 ST+ 00 # sum = sum + ...
33 6
34 RCL 4
35 -
36 STO 04 # toggle between 4 and 2
37 RCL 03
38 ST+ 01 # A = A + h
39 DSE 05    # N = N - 1 and test N=0
40 GTO 00 # end of loop
41 RCL 00
42 RCL 03
43 *
44 3
45 /
46 RTN
47 LBL E             # Calculate f(x). You can edit code after this label.
49 1/X
50 RTN
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Compact Simpson's Rule - Namir - 12-13-2015 02:06 AM
RE: Compact Simpson's Rule - Thomas Klemm - 12-13-2015, 07:13 AM
RE: Compact Simpson's Rule - Dieter - 12-13-2015, 02:20 PM



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