12-13-2017, 01:42 PM
Post: #1 Eddie W. Shore Senior Member Posts: 1,012 Joined: Dec 2013
Introduction

The program QUADSUM calculates the area under the curve described by the set of points (x_n, y_n). The points are connected, in groups of three, by quadratic splines. Thus, points (x1, y1), (x2, y2), and (x3, y3) are connected by a quadratic spline, (x3, y3), (x4, y4), (x5, y5) are connected by another quadratic spline, and so on.

The number of points for QUADSUM must be odd.

Code:
 EXPORT QUADSUM(LX,LY) BEGIN // EWS 2017-12-10 // Area by connecting  // points using quadratic  // curves // number of points must be odd LOCAL A,S,T; // A=0 S:=SIZE(LX); IF FP(S/2)==0 THEN RETURN "Invalid: Number of points must be odd"; KILL; END; LOCAL T,M,MA,MB,MC; FOR T FROM 1 TO S-2 STEP 2 DO M:=CAS.LSQ([[1,LX(T),LX(T)^2], [1,LX(T+1),LX(T+1)^2], [1,LX(T+2),LX(T+2)^2]], [[LY(T)],[LY(T+1)],[LY(T+2)]]); MA:=M(3,1); MB:=M(2,1); MC:=M(1,1); A:=A+ (MA*LX(T+2)^3/3+MB*LX(T+2)^2/2+ MC*LX(T+2))- (MA*LX(T)^3/3+MB*LX(T)^2/2+ MC*LX(T)); END; RETURN A; END;

Example

Find the area under the curve with these points connected by quadratic splines:
(0,2), (1,1), (2,2), (3,6), (4,4)

Note that the point (2,2) ends the first spline and starts the second.

FYI: The polynomial described would be the piecewise equation:
y = { x^2 -2x + 2 for 0 < x ≤ 2, -3x^2 + 19x – 24 for 2 < x ≤ 4
12-14-2017, 06:57 AM
Post: #2
 AlexFekken Member Posts: 151 Joined: May 2016
Doesn't this mean you are basically doing a repeated Simpson's rule, but with more work?

https://en.wikipedia.org/wiki/Simpson%27s_rule
12-20-2017, 05:03 AM
Post: #3
 AlexFekken Member Posts: 151 Joined: May 2016