# Using Integrals and Sums in MML

*This page is for the current JSim version 2.0. Click here for the earlier JSim 1.6 version.*

## Introduction

This document describes using JSim MML's built-in integral() and sum() functions.

Prerequisites:

- Introductory Survey of MML (required)
- Introduction to the JSim GUI (recommended)

Contents:

## Integrals

Integration of an integrand "expr" over realDomain t from t=lowbound to t=hibound is written as follows:

integral(t=lowbound to hibound, expr)

Integration over the entire range of t (from t.min to t.max) may be written compactly as:

integral(expr@t) // same as integral(t=t.min to t.max, expr)

Simple examples of integral() are demonstrated below:

*(Java plugin required)*

Here **v(t)** represents the integral of **u** up to the current time.
**w1** and **w2** are calculated identically and represent the integral
**u** over all time. All integrated variables will be assigned units m*sec, since an integral's
units are the product of the units of the integrated quantity and the units of the variable of integration.
Like other MML functions, integral() will generate unit conversion errors if it is used in an inappropriate
context. The integral() is a first order approximation and approaches the true integral of **u** as t.delta -> 0 . This can be shown by letting **z(t)** represent the integral **u** over all time, expressed as an ordinary differential equation (ODE), and running the model at ever smaller t.delta values. Note that the result of an integral obtained by an ODE equation is solver dependent (Euler accuracy is usually much worse than Radau).

While integrating from t.min to t.max or from t.min to t are the most common uses, the integrals may be between any two values to t. Also, the expression integrated need not be a simple variable, for example:

integral(t=t.min+1 to t/2, u^2*exp(-v))

MML integral() can also be used to "integrate out" one domain of a multi-dimensional variable:

*(Java plugin required)*

## Sums

Using the sum and integral operators to integrate a function IS NOT RECOMMENDED and is illustrated by the following example.

*(Java plugin required)*

The sum operator is used extensively in the models found by searching with the keyword "Fourier."

The summation of a summand "expr" over realDomain t from t=lowbound to t=hibound is written as follows:

sum(t=lowbound to hibound, expr)

Summation over the entire range of t (from t.min to t.max) may be written compactly as:

sum(expr@t) // same as sum(t=t.min to t.max, expr)

Simple examples of sum() are demonstrated below:

*(Java plugin required)*

Here **v(t)** represents the sum of **u** up to the current time.
**w1** and **w2** are calculated identically and represent the sum
**u** over all time. All summed variables will be assigned units m, since a sum's units are
equal to those of the summand. Like other MML functions, sum() will generate unit conversion errors if
it is used in an inappropriate context.

While summing from t.min to t.max or from t.min to t are the most common uses, sums may be between any two values to t. Also, the summand need not be a simple variable, for example:

sum(t=t.min+1 to t/2, u^2*exp(-v))

MML () can also be used to "sum out" one domain of a multi-dimensional variable:

*(Java plugin required)*Comments or Questions?

[This page was last modified 24Feb15, 3:38 pm.]

**Model development and archiving support at
physiome.org provided by the following grants:** NIH/NIBIB BE08407 Software Integration,
JSim and SBW 6/1/09-5/31/13; NIH/NHLBI T15 HL88516-01 Modeling for Heart, Lung and Blood: From Cell to Organ,
4/1/07-3/31/11; NSF BES-0506477 Adaptive Multi-Scale Model Simulation,
8/15/05-7/31/08; NIH/NHLBI R01 HL073598 Core 3: 3D Imaging and Computer
Modeling of the Respiratory Tract, 9/1/04-8/31/09; as well as prior
support from NIH/NCRR P41 RR01243 Simulation Resource in Circulatory Mass
Transport and Exchange, 12/1/1980-11/30/01 and NIH/NIBIB R01 EB001973
JSim: A Simulation Analysis Platform, 3/1/02-2/28/07.