# Blog

All Blog Posts | Next Post | Previous Post# Symbolic integration in TMS Analytics & Physics 3.0

Bookmarks:#### Tuesday, September 10, 2019

The main new feature of TMS Analytics & Physics 3.0 is symbolic integration. The version allows calculate symbolic expressions of indefinite and definite integrals and analytically evaluate definite integrals on the specified intervals.Symbolic integration can be implemented with very simple code. Here is the example of typical code template to get symbolic expression of an indefinite integral:

var f, i: string; begin f:= ...; try i:= translator.Integral(f, 'x'); except on ex:Exception do ; // handle the exception ‘ex’ end; // using symbolic expression ‘i’ of the integral end;

f = ‘(A*x+1)^(1/3)+1/(2-x/B)^(2/3)’ i = ‘3/4*(A*x+1)^(4/3)/A-(2-x/B)^(1/3)*3*B’ f = ‘(e^x-e^-x)*x^2-A*B^(x/2-1)’ i = ‘x^2*e^x-2*(x*e^x-e^x)+x^2*e^-x-2*(-x*e^-x-e^-x)-A*B^(x/2-1)/ln(B)*2’ f = ‘2*sin(x)-B*cos(a-x/2)+tan(x/2)^2’ i = ‘-2*cos(x)+B*sin(a-x/2)*2+2*(tan(1/2*x)-1/2*x)’

var f, x1, x2, i: string; begin f:= 'A*e^x-sin(x)/2'; x1:= 'Pi'; x2:= 'sin(y)'; try i:= translator.Integral(f, 'x', x1, x2); except on ex:Exception do ; // handle the exception ‘ex’ end; // using symbolic expression ‘i’ of the definite integral end;

Note that the integration limits must not depend on the integration variable (‘x’ in the examples). The limits can contain other variable names, functions, operators and other expressions. If the limits are constant and no other variable used in the integrand, then the result expression can be simplified. For example, using f=’2*x^2’, x1=’3’, x2=’5’ in the code above, we get i=’196/3’. Nevertheless, the result value is symbolic expression. To evaluate definite integrals (calculate numerical value), one must use the ‘Integrate’ method of the TTransaltor class as in the following code:

var f, x1, x2: string; iv: TValue; i: TFloat; begin f:= '2*x^2'; x1:= '3'; x2:= '5'; try iv:= translator.Integrate(f, 'x', x1, x2); i:= iv.AsType(); except on ex:Exception do ; // handle the exception ‘ex’ end; // using float value ‘i’ of the definite integral end;

Note that when evaluating definite integrals the integrand expression can contain other variable or even functions of other variables. However, these variables must be added to the translator instance for the evaluation process. For example, adding the following variables

translator.Add('A',-1); translator.Add('B', 2); translator.Add('n', 3);

TMS Analytics & Physics library realizes base integration rules (sum rule, multiplication by constant and so on); provides default integrators for all algebraic, base special and transcendental functions; realizes integration by-parts algorithms for special expression types. The library also allows implementing user-defined integrators for special cases of functions and expressions. Thus, the functionality of symbolic integration can be easily extended.

The version 3.0 is already available. Source code of the demo project for the article can be downloaded from here.

Bruno Fierens

Bookmarks:

#### This blog post has not received any comments yet.

All Blog Posts | Next Post | Previous Post