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:
// simple examples of integral() operator
unit conversion on;
import nsrunit;
math integral1 {
realDomain t sec; t.min=0; t.max=5; t.delta=1; // time (seconds)
real u(t) = t^2 * (1 m/sec^2); // u (meters)
real v(t) = integral(t=t.min to t, u); // v (meter*sec)
real w1 = integral(t=t.min to t.max, u); // w (meter*sec)
real w2 = integral(u@t); // w (meter*sec)
}
(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.
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:
// "integrating out" one variable domain
unit conversion on;
import nsrunit;
math integral2 {
realDomain t sec; t.min=0; t.max=6; t.delta=1; // time (seconds)
realDomain x m; x.min=0; x.max=1; x.delta=0.1; // space (meters)
real u(t,x) = t^2*(1 mole/sec^2) + x^2*(1 mole/m^2); // u (mole)
real v(t) = integral(x=x.min to x.max, u); // v (mole*meters)
}
(Java plugin required)
Sums
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:
// simple examples of sum() operator
unit conversion on;
import nsrunit;
math sums {
realDomain t sec; t.min=0; t.max=5; t.delta=1; // time (seconds)
real u(t) = t^2 * (1 m/sec^2); // u (meters)
real v(t) = sum(t=t.min to t, u); // v (meter)
real w1 = sum(t=t.min to t.max, u); // w1 (meter)
real w2 = sum(u@t); // w2 (meter)
}
(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:
// "summing out" one variable domain
unit conversion on;
import nsrunit;
math sum2 {
realDomain t sec; t.min=0; t.max=6; t.delta=1;
realDomain x m; x.min=0; x.max=1; x.delta=0.1;
real u(t,x) = t^2*(1 mole/sec^2) + x^2*(1 mole/m^2); // u in mole
real v(t) = sum(x=x.min to x.max, u); // v in mole
}
(Java plugin required)
Comments or Questions? [This page was last modified 06Jul12, 3:13 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.
