diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /info/maad/pgm1.bas |
Initial commit
Diffstat (limited to 'info/maad/pgm1.bas')
-rw-r--r-- | info/maad/pgm1.bas | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/info/maad/pgm1.bas b/info/maad/pgm1.bas new file mode 100644 index 0000000000..f8892e7549 --- /dev/null +++ b/info/maad/pgm1.bas @@ -0,0 +1,20 @@ +100 DEFDBL A-H, O-Z
+105 DEF FNA (x AS DOUBLE) = SQR(1! - (SIN(EXP(1) / 2!) * SIN(x)) ^ 2)
+110 A = 0!: REM This is the lower endpoint of [a,b].
+120 B = 3.141592653589793# / 2!: REM This is the upper endpoint of [a,b].
+130 SUM = 0!: REM This is an accumulator.
+135 REM The user is asked for a number of intervals, n, even and > 0.
+140 INPUT "Enter number of intervals (must be even) "; N
+145 IF N <= 0 OR (2 * FIX(N / 2) - N < 0) THEN PRINT "Input error": GOTO 140
+150 H = (B - A) / N: REM The sub-interval size h = (b-a)/n.
+160 FOR I = 1 TO N STEP 2: REM The "FOR" loop is done n/2 times.
+170 SUM = SUM + FNA(A + (I - 1) * H)
+175 REM: PRINT A + (I - 1) * H, FNA(A + (I - 1) * H)
+180 SUM = SUM + 4! * FNA(A + I * H)
+185 REM: PRINT A + I * H, FNA(A + I * H)
+190 SUM = SUM + FNA(A + (I + 1) * H)
+195 REM: PRINT A + (I + 1) * H, FNA(A + (I + 1) * H)
+200 NEXT I: REM After loop, the sum is y_0+4*y_1+2*y_2+...+4*y_{n-1}+y_n.
+210 PRINT "Sum = "; SUM: PRINT " Value of integral = "; SUM * H / 3
+220 REM This short program will integrate a function FNA(x) from x = a to b.
+
|