Click below to go directly to a specific section:
This code demonstrates the simplicity of outputing THE FINITE AND INFINITE SUMS.
This program to compute the three finite sums SUM6, SUM7, and SUM8, the infinite sum SUMINF and the difference between the infinite sum and each of the finite sums. SUM6 = .9 + .09 + .009 + .0009 + .00009 + .000009; SUM7 = .9 + .09 + .009 + .0009 + .00009 + .000009 + .0000009; SUM6 = .9 + .09 + .009 + .0009 + .00009 + .000009 + .0000009 + .00000009; SUMINF = .9 + .09 + .009 + .0009 + ... = .99999...... = 1 at infinity!
******ERRORS INDUCED BY ARITHMETIC OPERATONS ON SAMLL NUMBERS
REAL SUM6,SUM7,SUM8,DIF6,DIF7,DIF8,SUMINF
*
OPEN(6,FILE='PRN')
SUM6=.9*(1.-0.1**6)/0.9
SUM7=.9*(1.-0.1**7)/0.9
SUM8=.9*(1.-0.1**8)/0.9
******COMPUTER SUM OF INFINITE TERMS
SUMINF=0.9/(1.0-0.1)
******COMPUTE DIFFERENCES BETWEEN FINITE & INFINITE SUMS
DIF6 = SUMINF - SUM6
DIF7 = SUMINF - SUM7
DIF8 = SUMINF - SUM8
WRITE(6,*) 'INFINITE SUM = ', SUMINF
WRITE(6,*) 'SUM6 = ', SUM6, ' INFINITE SUM - SUM6 = ', DIF6
WRITE(6,*) 'SUM7 = ', SUM7, ' INFINITE SUM - SUM7 = ', DIF7
WRITE(6,*) 'SUM8 = ', SUM8, ' INFINITE SUM - SUM8 = ', DIF8
STOP
END
Output
INFINITE SUM = 1.0000000
SUM6 = 9.99990E-001 INFINITE SUM - SUM6 = 1.03270E-006
SUM7 = 9.99990E-001 INFINITE SUM - SUM7 = 1.192093E-007
SUM8 = 1.0000000. INFINITE SUM - SUM8 = .0000000
This program has NOT been tested due to the inability to locate the necessary compiler.
It is posted here just to give you an example of
what Fortran source code looks like. Compare it to the other example listed to see the
syntactic differences that exist in the language.
Last modified: 12/10/97 3:36:38 AM