Summation & Product iterated operators

TO SUPPORT MY WORK, ORDER A COMMERCIAL LICENSE
THANK YOU!

The tutorial consists of more than 200 live examples from 50 sections. Each of the examples can be copied and run on your own environment. In addition, mXparser provides an extensive collection of over 500 built-in math functions, expressions and symbols. Familiarize yourself with the scope and the syntax. Live testing is the best way to learn. Good luck! 🙂

Tutorial Math Collection API spec Download

Below is the code for JAVA, the code for C# is almost identical. To copy the code, double-click inside the frame.

Case 1: SIGMA summation operator

$$\sum_{i=k}^{n}f(x_1,x_2,,\ldots,i)$$

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Expression e1 = new Expression("sum(i, 1, 10, 2*i)");
mXparser.consolePrintln("Res 1: " + e1.getExpressionString() + " = " + e1.calculate());
         
/* Iteration can be done by not necessarily whole increment */
Expression e2= new Expression("sum(i, 1, 10, i, 0.5)");
mXparser.consolePrintln("Res 2: " + e2.getExpressionString() + " = " + e2.calculate());
[mXparser-v.5.2.1] Res 1: sum(i, 1, 10, 2*i) = 110.0
[mXparser-v.5.2.1] Res 2: sum(i, 1, 10, i, 0.5) = 104.5

Case 2: PI product operator

$$\prod_{i=k}^{n}f(x_1,x_2,,\ldots,i)$$

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...

/* factorial */
Expression e1 = new Expression("prod(i, 1, 5, i)");
mXparser.consolePrintln("Res 1: " +  e1.getExpressionString() + " = " + e1.calculate());
         
/* Iteration can be done by not necessarily whole increment */
/* Here different form of 10! */
Expression e2 = new Expression("prod(i, 1, 5, 2*i, 0.5)");
mXparser.consolePrintln("Res 2: " + e2.getExpressionString() + " = " + e2.calculate());
[mXparser-v.5.2.1] Res 1: prod(i, 1, 5, i) = 120.0
[mXparser-v.5.2.1] Res 2: prod(i, 1, 5, 2*i, 0.5) = 3628800.0

Case 3: SIGMA summation operator – Approximating sin(x) by Taylor series

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Argument x = new Argument("x = 2*pi");
Argument n = new Argument("n = 3");
Expression e = new Expression("sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! )", x, n);
mXparser.consolePrintln("Res 1: " + e.getExpressionString() + " = " + e.calculate());
 
/* Increasing polynomial order ... */
n.setArgumentValue(5);
mXparser.consolePrintln("Res 2: " + e.getExpressionString() + " = " + e.calculate());
 
/* Increasing polynomial order ... */
n.setArgumentValue(10);     
mXparser.consolePrintln("Res 3: " + e.getExpressionString() + " = " + e.calculate());
         
/* Increasing polynomial order ... */
n.setArgumentValue(20);     
mXparser.consolePrintln("Res 4: " + e.getExpressionString() + " = " + e.calculate());
         
/* Checking other point closer to '0' */
x.setArgumentValue(2);
mXparser.consolePrintln("Res 5: " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.2.1] Res 1: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = 30.159127410206484
[mXparser-v.5.2.1] Res 2: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = 3.195076042131831
[mXparser-v.5.2.1] Res 3: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = -8.27409522186923E-5
[mXparser-v.5.2.1] Res 4: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = 0.0
[mXparser-v.5.2.1] Res 5: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = 0.0

Case 4: SIGMA summation operator – Approximating pi value by integrating sqrt(1-x^2)

// JAVA: import org.mariuszgromada.math.mxparser.*;
// C#: using org.mariuszgromada.math.mxparser;
// ...
Argument d = new Argument("d",0.1);
Expression e = new Expression("2 * sum(x, -1, 1, d*sqrt(1-x^2), d)", d);
mXparser.consolePrintln("Res 1: d = " + d.getArgumentValue() + ", " + e.getExpressionString() + " = " + e.calculate());
d.setArgumentValue(0.01);
mXparser.consolePrintln("Res 2: d = " + d.getArgumentValue() + ", " + e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.2.1] Res 1: d = 0.1, 2 * sum(x, -1, 1, d*sqrt(1-x^2), d) = 3.1045183304630037
[mXparser-v.5.2.1] Res 2: d = 0.01, 2 * sum(x, -1, 1, d*sqrt(1-x^2), d) = 3.1404170317790436
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.2.1

Nuget – .NET CLI

dotnet add package MathParser.org-mXparser --version 5.2.1

Nuget – Package Reference

<PackageReference Include="MathParser.org-mXparser" Version="5.2.1"/>

Maven – Dependency

<dependency>
<groupid>
org.mariuszgromada.math</groupid>
<artifactid>
MathParser.org-mXparser</artifactid>
<version>
5.2.1</version>
</dependency>

Maven – Gradle

implementation 'org.mariuszgromada.math:MathParser.org-mXparser:5.2.1'

Maven – Gradle (Kotlin)

implementation("org.mariuszgromada.math:MathParser.org-mXparser:5.2.1")

GitHub

git clone https://github.com/mariuszgromada/MathParser.org-mXparser

OTHER DOWNLOAD OPTIONS

Download latest release – v.5.2.1 Orion: .NET bin onlyDownload latest release – v.5.2.1 Orion: JAVA bin onlyDownload latest release – v.5.2.1 Orion: bin + doc

NEWS FROM MATHPARSER.ORG
SOURCE CODE

Source code .zipSource code .tar.gz
View on GitHubMathSpace.pl

DONATION
Did you find the software useful?
Please consider donation 🙂
DONATE