Summation & Product iterated operators

MathParser.org - mXparser - logo - Tutorial

*** If you found the software useful donation is something you might consider 🙂 ***

If you found the software useful donation is something you might consider :-)

JAVA code

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());
Res 1: sum(i, 1, 10, 2*i) = 110.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());
Res 1: prod(i, 1, 5, i) = 120.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());
Res 1: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = 30.159127410206487
Res 2: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = 3.1950760421318374
Res 3: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = -8.274095221352927E-5
Res 4: sin(x) - sum(k, 0, n, (-1)^k*(x^(2*k+1))/(2*k+1)! ) = -3.5461741276769342E-15
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());
Res 1: d = 0.1, 2 * sum(x, -1, 1, d*sqrt(1-x^2), d) = 3.1045183304630037
Res 2: d = 0.01, 2 * sum(x, -1, 1, d*sqrt(1-x^2), d) = 3.1404170317790423

*** If you found the software useful donation is something you might consider 🙂 ***

If you found the software useful donation is something you might consider :-)

Enjoy! 🙂

 

Best regards,

Mariusz Gromada

Download latest release – v.4.0.0.2: bin + doc + src (.zip 10.7 MB)

Download latest release – v.4.0.0.2: bin only (.zip 3.04 MB) – separate binaries for java: 1.5, 1.6, 1.7, 1.8; .NET: 2.0, 3.0, 3.5, 4.0, 4.5, 4.6, .NET Core, .NET Standard, .NET PCL, Xamarin.Android, Xamarin.iOS

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