Summation & Product iterated operators

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

Tutorial Math Collection API spec Download

Below is the code for JAVA, the code for C# is almost identical.

Case 1: SIGMA summation operator

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

import 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.0.0] Res 1: sum(i, 1, 10, 2*i) = 110.0
[mXparser-v.5.0.0] 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)$$

import 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.0.0] Res 1: prod(i, 1, 5, i) = 120.0
[mXparser-v.5.0.0] Res 2: prod(i, 1, 5, 2*i, 0.5) = 3628800.0

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

import 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.0.0] Res 1: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = 30.159127410206484
[mXparser-v.5.0.0] Res 2: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = 3.195076042131831
[mXparser-v.5.0.0] Res 3: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = -8.27409522186923E-5
[mXparser-v.5.0.0] Res 4: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = 0.0
[mXparser-v.5.0.0] 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)

import 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.0.0] Res 1: d = 0.1, 2 * sum(x, -1, 1, d*sqrt(1-x^2), d) = 3.1045183304630037
[mXparser-v.5.0.0] Res 2: d = 0.01, 2 * sum(x, -1, 1, d*sqrt(1-x^2), d) = 3.1404170317790436
Nuget
Install-Package MathParser.org-mXparser -Version 5.0.2
Maven
<dependency>
<groupid>org.mariuszgromada.math</groupid>
<artifactid>MathParser.org-mXparser</artifactid>
<version>5.0.2</version>
</dependency>
Gradle
implementation 'org.mariuszgromada.math:MathParser.org-mXparser:5.0.2'
Gradle (Kotlin)
implementation("org.mariuszgromada.math:MathParser.org-mXparser:5.0.2")
GitHub
git clone https://github.com/mariuszgromada/MathParser.org-mXparser
OTHER DOWNLOAD OPTIONS

Download latest release – v.5.0.2 Leonis: bin + docDownload latest release – v.5.0.2 Leonis: bin only, includes separate binaries for various .NET platforms and Java versions

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