Post Reply 
Trapezoidal Rule and Simpson's Rule
06-06-2016, 04:19 AM
Post: #1
Trapezoidal Rule and Simpson's Rule
Trapezoidal Rule
Link to blog entry: http://edspi31415.blogspot.com/2016/06/h...oidal.html
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
Link to blog entry: http://edspi31415.blogspot.com/2016/06/h...-rule.html
Code:
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;
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)