The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function

 Trapezoidal Rule and Simpson's Rule
06-06-2016, 04:19 AM
Post: #1
 Eddie W. Shore Senior Member Posts: 1,596 Joined: Dec 2013
Trapezoidal Rule and Simpson's Rule
Trapezoidal Rule
Code:
EXPORT TRAPRULE() BEGIN // EWS 2016-06-05 HAngle:=0; // Radians LOCAL f; INPUT({{f,[8]},A,B,N}, "Trapezoidal Rule", {"f(X)=","Low:","High:", "Intervals:"}); H:=(B-A)/N; X:=A; T:=EVAL(f); X:=B; T:=EVAL(f)+T; FOR I FROM 1 TO N-1 DO X:=A+I*H; T:=2*EVAL(f)+T; END; T:=T*H/2; RETURN T; END;

Simpson's Rule
EXPORT SIMPRULE() BEGIN // EWS 2016-06-05 HAngle:=0; // Radians LOCAL f; INPUT({{f,[8]},A,B,N}, "Simpson Rule", {"f(X)=","Low:","High:", "Intervals (Even):"}); H:=(B-A)/N; X:=A; T:=EVAL(f); X:=B; T:=EVAL(f)+T; FOR I FROM 1 TO N-1 DO X:=A+I*H;  IF FP(I/2)==0 THEN T:=2*EVAL(f)+T; ELSE T:=4*EVAL(f)+T; END; END; T:=T*H/3; RETURN T; END;