Summation & Product iterated operators

FOR COMMERCIAL USE, PLEASE ENSURE YOU HAVE A COMMERCIAL LICENSE.
ANOTHER WAY TO SUPPORT MY WORK IS BY PURCHASING MY BOOK, CUSTOMER FIRST, VALUE NEXT.
THANK YOU FOR SUPPORTING MY WORK!

The tutorial consists of more than 200 live examples from 50 sections given separately for JAVA, C# and C++. 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, C# (the code for C# is almost identical) and C++. 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/C# code
// 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());
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ExpressionPtr 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 */
ExpressionPtr e2 = new_Expression("sum(i, 1, 10, i, 0.5)");
mXparser::consolePrintln("Res 2: " + e2->getExpressionString() + " = " + e2->calculate());
Code result
[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/C# code
// 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());
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...

/* factorial */
ExpressionPtr 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! */
ExpressionPtr e2 = new_Expression("prod(i, 1, 5, 2*i, 0.5)");
mXparser::consolePrintln("Res 2: " + e2->getExpressionString() + " = " + e2->calculate());
Code result
[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/C# code
// 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());
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ArgumentPtr x = new_Argument("x = 2*pi");
ArgumentPtr n = new_Argument("n = 3");
ExpressionPtr 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());
Code result
[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/C# code
// 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());
C++ code
#include "org/mariuszgromada/math/mxparser.hpp"
// ...
ArgumentPtr d = new_Argument("d",0.1);
ExpressionPtr 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());
Code result
[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 (C#, F#, Visual Basic, …)

Install-Package MathParser.org-mXparser-Version 6.1.1

Nuget – .NET CLI

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

Nuget – Package Reference

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

Maven – Dependency (Java, Kotlin, Scala, Groovy, …)

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

Maven – Gradle

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

CMake – Dependency / FetchContent (C++, MSVC, LLVM/Clang, GNU/GCC, MinGW, MSYS2, WSL, Windows, Linux, Unix, MacOS)

include(FetchContent)
FetchContent_Declare(
MathParserOrgMxParser
GIT_REPOSITORY
https://github.com/mariuszgromada/MathParser.org-mXparser.git
GIT_TAG
v.6.1.1
SOURCE_SUBDIR CURRENT/cpp/lib
)
FetchContent_MakeAvailable(
MathParserOrgMxParser)
mxparser_link(YourExecutable)

GitHub

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

OTHER DOWNLOAD OPTIONS

Download latest release – v.6.1.0 Sagitara: .NET bin onlyDownload latest release – v.6.1.0 Sagitara: JAVA bin onlyDownload latest release – v.6.1.0 Sagitara: bin + doc

NEWS FROM MATHPARSER.ORG
SOURCE CODE

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

My other creative spaces

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