simpson & trapezoidal comparison 10 rem - soltn to ex5 - numeric integration - j.h.stacey keynes 12 print "enter prog q5" 15 print "exact answer is .35,intermediate aproximations shown below" 18 print "intervals","simpson","trapezoidal" 20 def fna(x) = 0.35*x*sin(x) 30 let p = 3.14159265 35 rem - z1 = sum of 1st & (m+1)th terms 37 let z1 = fna(0)+fna(p/2) 40 let m = 2 50 rem - set s1 at nominal value to start succesive approximation loop 60 gosub 200 70 let s1 = 2*s 80 rem - i protects against non convergence of succesive approximations 82 rem - j protects against run time error 85 for i = 1 to 100 90 let m = 2*m 100 gosub 200 110 if abs((s-s1)/s) <= 1?-3 then 140 120 let s1 = s 125 let t1 = t 130 next i 132 print "with 2^100 intervals,consecutive terms still not within .1%" 140 print "with";m;" subdivisions error relative to previous"; 150 print " integration with:-" 155 print "simpsons method"; 157 print abs(100*(s-s1)/s);" per cent" 160 print "trapezium method "; 165 print abs(100*(t-t1)/t);" per cent" 170 print "exit from prog q5" 175 end 200 rem - evaluate jth integral 205 rem - z2 = sum of 2nd,4th . . . mth terms 207 rem - z3 = sum of 3rd,5th . . . (m-1)th terms 220 let h = p/(2*m) 225 let z2 = 0 230 for j = h to h*m step 2*h 240 let z2 = z2+fna(j) 250 next j 270 let z3 = 0 280 for j = 2*h to h*(m-1) step 2*h 290 let z3 = z3+fna(j) 300 next j 310 let s = (z1+4*z2+2*z3)*h/3 320 let t = (z1+2*z2+2*z3)*h/2 330 print m,s,t 340 return