Post Reply 
Simpson revival
09-29-2016, 10:27 PM (This post was last modified: 09-29-2016 10:30 PM by Namir.)
Post: #9
RE: Simpson revival
A modified version of the BASIC program works if we have two tests:

If Abs(Z - W) <= P Then
....

And

If Abs(Z - (16 * Z - W) / 15) <= P Then
...

I tested f(x)=1/X for integrals in [1,2], [1,10], and [1,100]. In each case the absolute value of the ratio of the error of the calculated integral divided by the error of the improved integral is in the order of 1000!

I suggest omitting the first test altogether!

Here is an updated Basic version that reflects Dieter's suggestion and my above comments:

Code:
10 INPUT A
20 INPUT B
30 P=1E-5 'Expected tolerance
40 R=0: L=1: N=1: W=1E99 'Initializing
50 X=A: GOSUB 1000: T=Y 'Call Y=f(X) subroutine with X=A
60 X=B: GOSUB 1000: T=T+Y 'T=f(A)+f(B) now
70 N=N*2: H=(B-A)/N 'New step: Double the number of intervals
80 X=A+H: S=0 'Start with 1st new (odd) point
90 FOR I=1 TO L 'Calculate Sum of f(x) for new (odd) points
100 GOSUB 1000: S=S+Y
110 X=X+2*H 'Next new (odd) point
120 NEXT I
130 S=S*4: U=T+R/2 'Odd points have a coefficient of 4; Even points come from old odd points but with a coefficient of 2 instead of 4
140 Z=H*(S+U)/3 'New Integral value at this step
145 Y=(16*Z-W)/15 ' Calculate improved integral
150 IF ABS(Z-Y)<=P THEN PRINT "Integral value: ";Y: STOP 'OK with expected tolerance
160 W=Z: T=U: R=S: L=N 'Prepare new step
170 GOTO 70 'New step, please

1000 Y=f(X) 'Calculate f(X) subroutine
1010 RETURN


Namir
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Simpson revival - Pekis - 09-28-2016, 08:04 AM
RE: Simpson revival - Namir - 09-28-2016, 10:40 AM
RE: Simpson revival - Dieter - 09-28-2016, 12:25 PM
RE: Simpson revival - Namir - 09-28-2016, 02:00 PM
RE: Simpson revival - Namir - 09-28-2016, 03:50 PM
RE: Simpson revival - Dieter - 09-28-2016, 10:00 PM
RE: Simpson revival - Albert Chan - 07-31-2018, 02:57 PM
RE: Simpson revival - Namir - 09-29-2016, 04:44 PM
RE: Simpson revival - Dieter - 09-29-2016, 06:23 PM
RE: Simpson revival - Namir - 09-29-2016 10:27 PM
RE: Simpson revival - Dieter - 09-30-2016, 06:00 AM
RE: Simpson revival - Dieter - 10-02-2016, 03:29 PM
RE: Simpson revival - Namir - 10-02-2016, 04:48 PM
RE: Simpson revival - Namir - 10-09-2016, 03:14 AM
RE: Simpson revival - Albert Chan - 08-04-2018, 05:29 PM



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