restart: # SIMPSON'S COMPOSITE ALGORITHM 4.1 # # To approximate I = integral ( ( f(x) dx ) ) from a to b: # # INPUT: endpoints a, b: even positive integer n. # # OUTPUT: approximation XI to I. print(`This is Simpsons Method. \134n`): print(`Input the function F(x) in terms of x `): print(`For example: cos(x) `): F := scanf(`%a`)[1]:print(`F(x) = `):print(F): F := unapply(F,x): OK := FALSE: while OK = FALSE do print(`Input lower limit of integration and `): print(`upper limit of integration `): print(`separated by a blank `): A := scanf(`%f`)[1]: B := scanf(`%f`)[1]:print(`a = `):print(A):print(`b = `):print(B): if A > B then print(`Lower limit must be less than upper limit `): else OK := TRUE: fi: od: OK := FALSE: while OK = FALSE do print(`Input an even positive integer N. `): N := scanf(`%d`)[1]:print(`N = `):print(N): if N > 0 and N mod 2 = 0 then OK := TRUE: else print(`Input must be even and positive `): fi: od: if OK = TRUE then # Step 1 H := (B-A)/N: # Step 2 XI0 := F(A) + F(B): # Summation of f(x(2*I-1)) XI1 := 0.0: # Summation of f(x(2*I)) XI2 := 0.0: # Step 3 NN := N - 1: for I1 from 1 to NN do # Step 4 X := A + I1 * H: # Step 5 if I1 mod 2 = 0 then XI2 := XI2 + F(X): else XI1 := XI1 + F(X): fi: od: # Step 6 XI := (XI0 + 2.0 * XI2 + 4.0 * XI1) * H / 3.0: # Step 7 print(` The integral of F from a = `):print(A):print(` to b = `):print(B): print(`equals`):print(XI): fi: STtUaGlzfmlzflNpbXBzb25zfk1ldGhvZC5+fCtHNiI= SUdJbnB1dH50aGV+ZnVuY3Rpb25+Rih4KX5pbn50ZXJtc35vZn54fkc2Ig== STVGb3J+ZXhhbXBsZTp+Y29zKHgpfkc2Ig== SShGKHgpfj1+RzYi LUkkc2luRzYkJSpwcm90ZWN0ZWRHSShfc3lzbGliRzYiNiNJInhHRic= SUZJbnB1dH5sb3dlcn5saW1pdH5vZn5pbnRlZ3JhdGlvbn5hbmR+RzYi STx1cHBlcn5saW1pdH5vZn5pbnRlZ3JhdGlvbn5HNiI= STZzZXBhcmF0ZWR+Ynl+YX5ibGFua35HNiI= SSVhfj1+RzYi JCIiIUYj SSVifj1+RzYi JCIrYWlmVEohIio= SUNJbnB1dH5hbn5ldmVufnBvc2l0aXZlfmludGVnZXJ+Ti5+RzYi SSVOfj1+RzYi IiM/ ST1+VGhlfmludGVncmFsfm9mfkZ+ZnJvbX5hfj1+RzYi JCIiIUYj SSl+dG9+Yn49fkc2Ig== JCIrYWlmVEohIio= SSdlcXVhbHNHNiI= JCIrJXkxKysjISIq JSFH