You can use Mathcad’s integral operator to numerically evaluate the definite integral of a function over some interval.

As an example, here’s how you would evaluate the definite integral of sin(x)2 from 0 to n/2 . Follow these steps:

• Click in a blank space and type &. An integral appears, with placeholders for the integrand, the limits of integration, and the variable of integration.

• Click on the bottom placeholder and type O. Click on the top placeholder and type [Ctrl] p/4. These are the upper and lower limits of integration.

Mathcad uses a numerical algorithm called Romberg integration to approximate the integral of an expression over an interval of real numbers.

There are some important things to remember about integration in Mathcad:

• The limits of integration must be real. The expression to be integrated can, however, be either real or complex.

• Except for the integrating variable, all variables in the integrand must have been defined elsewhere in the worksheet.

• The integrating variable must be a single variable name.

• If the integrating variable involves units, the upper and lower limits of integration must have the same units.

Like all numerical methods, Mathcad’s integration algorithm can have difficulty with ill-behaved integrands. If the expression to be integrated has singularities, discontinuities, or large and rapid fluctuations, Mathcad’s solution may be inaccurate.

Because Mathcad’s integration method divides the interval into four subintervals and then successively doubles the number of points, it can return incorrect answers for periodic functions with having periods 1/2n times the length of the interval. To avoid this problem, divide the interval into two uneven subintervals and integrate over each subinterval separately.

In some cases, you may be able to find an exact numerical value for your integral by using Mathcad’s symbolic integration capability. You can also use this capability to evaluate indefinite integrals. See Chapter 17, “Symbolic Calculation.”

**Variable limits of integration**

Although the result of an integration is a single number, you can always use an integral with a range variable to obtain results for many numbers at once. You might do this, for example, when you set up a variable limit of integration. Figure 12-7 shows how to do this.

Keep in mind that calculations such as those shown in Figure 12-7 may require repeatedly evaluating an integral. This may take considerable time depending on the complexity of the integrals, the length of the interval, and the value of TOL (see below).

**Changing the tolerance for integrals**

Mathcad’s numerical integration algorithm makes successive estimates of the value of the integral and returns a value when the two most recent estimates differ by less than the value of the built-in variable TOL. Figure 12-8 shows how changing TOL affects the accuracy of integral calculations. To display many digits of precision

You can change the value of the tolerance by including definitions for TOL directly in .A your worksheet as shown on Figure 12-8. You can also change the tolerance by using the Built-In Variables tab when you choose **Options** from the Math menu. To see the effect of changing the tolerance, choose **Calculate Document** from the **Math** menu to recalculate all the equations in the worksheet.

IfMathcad’s approximations to an integral fail to converge to an answer, Mathcad marks the integral with an appropriate error message. Failure to converge can occur when the function has singularities or “spikes” in the interval or when the interval is extremely long.

When you change the tolerance, keep in mind the trade-off between accuracy and computation time. If you decrease (tighten) the tolerance, Mathcad will compute integrals more accurately. However, because this requires more work, Mathcad will take longer to return a result. Conversely, if you increase (loosen) the tolerance, Mathcad will compute more quickly, but the answers will be less accurate

**Contour integrals and double integrals**

You can use Mathcad to evaluate complex contour integrals. To do so, first parametrize the contour. Then integrate over the parameter. If the parameter is something other than arc length, you must also include the derivative of the parametrization as a correction factor. Figure 12-9 shows an example. Note that the imaginary unit i used in specifying the path must be typed as li.

You can also use Mathcad to evaluate double or multiple integrals. To set up a double. integral, press & twice. Fill in the integrand, the limits, and the integrating variable for .A each integral. Figure 12-10 shows an example

Keep in mind that double integrals take much longer to converge to an answer than single integrals. Wherever possible, use an equivalent single integral in place of a double integral.