Simpson revival
09-29-2016, 10:27 PM (This post was last modified: 09-29-2016 10:30 PM by Namir.)
Post: #9
 Namir Senior Member Posts: 813 Joined: Dec 2013
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
 « Next Oldest | Next Newest »

 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)
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://www.hpmuseum.org/forum/showthread.php?mode=threaded&tid=6939&pid=61973", "fetch_time": 1642844995000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2022-05/segments/1642320303779.65/warc/CC-MAIN-20220122073422-20220122103422-00404.warc.gz", "warc_record_offset": 875029877, "warc_record_length": 6093, "token_count": 982, "char_count": 2435, "score": 3.609375, "int_score": 4, "crawl": "CC-MAIN-2022-05", "snapshot_type": "latest", "language": "en", "language_score": 0.2660788893699646, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00016-of-00064.parquet"}