Page 153 - Excel for Scientists and Engineers: Numerical Methods
P. 153
130 EXCEL: NUMERICAL METHODS
Figure 7-3. Calculating the area under a curve.
(folder 'Chapter 07 Examples', workbook 'Area under Curve', worksheet 'Curve1 by worksheet')
The formula in cell C3, used to calculate the area increment by the
trapezoidal approximation, is
=( 62+63)/2*(A3-A2)
The area increments were summed to obtain the area under the curve.
Calculating the Area under a Curve
Defined by a Table of Data Points
by Means of a VBA Function Procedure
A simple VBA custom function to find the area under a curve defined by a
table of x, y data points, using the trapezoidal approximation, is shown in Figure
7-4. The syntax of the function is CurvArea(x-values, y-values).
Function CurvArea(x-values, y-values)
'Simple trapezoidal area integration
N1 = y-values.Count
For J = 2 To N1
area = area + (x-values(J) - x-values(J - 1)) (y-values(J) + y-values(J - 1)) I2
Next J
CurvArea = area
End Function
Figure 7-4. Simple VBA function CurvArea to calculate the area under a curve.
(folder 'Chapter 07 Examples', workbook 'Area under Curve', module 'CurvArea')