# pwl_product_integral

pwl_product_integral, a FORTRAN90 code which calculates the exact value of the integral of the product of two piecewise linear functions F(X) and G(X).

The piecewise linear function F(X) is defined by

• F_NUM, the number of nodes;
• F_X(1:F_NUM), the X coordinates of the nodes (in ascending order);
• F_V(1:F_NUM), the value of F at each node;

The piecewise linear function G(X) is defined similarly, and there is no requirement that G(X) uses the same nodes as F(X), or the same number of nodes.

The task, then, is to determine the value of

```        Integral ( A <= X <= B ) F(X) * G(X) dx
```
This value can be determined exactly, by breaking the interval ot integration into subintervals over which F(X) and G(X) are simple linear functions.

In finite element programs over 1-dimensional geometries, integrals like this may occur when assembling the stiffness matrix, but these integrals are generally treated using quadrature.

A more appropriate use for this function occurs when coarsening a finite element solution, or constructing a piecewise linear least squares finite element approximant to data that is regarded as a piecewise linear function.

In case 1, we treat the original finite element solution as the function F(X), and in case 2, we treat the data as a finite element function whose mesh is implicit in the X coordinates of the given data.

Our G_X is, in case 1, the coarse mesh and in case 2 the given mesh. To determine the finite element coefficient U(I) on this mesh, we must integrate our data function F(X) against the I-th basis function, which in this case is simply the I-th "hat function. So to use our formula for G(X), we set G_V(1:G_NUM) to 0, except that G_V(I) = 1, and compute

```        U(I) = Integral ( G_X(I-1) <= X <= G_X(I+1) ) F(X) * G(X) dx
```
Doing this for I from 1 to G_NUM allows us to compute the coefficients of the coarsened solution (case 1) or the least squares approximant to the piecewise linear function representing the data F.

### Languages:

pwl_product_integral is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version.

### Related Data and Programs:

FEM1D, a data directory which contains a description and examples of files that describe a finite element model.

FEM1D, a FORTRAN90 code which applies the finite element method to a 1D linear two point boundary value problem.

FEM1D_ADAPTIVE, a FORTRAN90 code which applies the finite element method to a 1D linear two point boundary value problem using adaptive refinement to improve the solution.

FEM1D_NONLINEAR, a FORTRAN90 code which applies the finite element method to a 1D nonlinear two point boundary value problem.

FEM1D_PMETHOD, a FORTRAN90 code which applies the p-method version of the finite element method to a linear two point boundary value problem in a 1D region.

FEM1D_PROJECT, a FORTRAN90 code which projects data into a finite element space, including the least squares approximation of data, or the projection of a finite element solution from one mesh to another.

FEM1D_SAMPLE, a FORTRAN90 code which samples a scalar or vector finite element function of one variable, defined by FEM files, returning interpolated values at the sample points.

### Reference:

1. Hans Rudolf Schwarz,
Finite Element Methods,
ISBN: 0126330107,
LC: TA347.F5.S3313.
2. Gilbert Strang, George Fix,
An Analysis of the Finite Element Method,
Cambridge, 1973,
ISBN: 096140888X,
LC: TA335.S77.
3. Olgierd Zienkiewicz,
The Finite Element Method,
Sixth Edition,
Butterworth-Heinemann, 2005,
ISBN: 0750663200,
TA640.2.Z54.

### Source Code:

Last revised on 20 August 2020.