How to manage these expressions?

84 views
Skip to first unread message

Andrés Mauricio Barragán Sarmiento

unread,
Oct 28, 2013, 4:59:01 AM10/28/13
to jep-...@googlegroups.com
Hello, I am currently using version 2.4.1, and I wonder if with this version I can do the following:

If for example I have a function 3(x + 0)(x + 1) + 5(x + 0), to simplify screen I get 3x(x +1) + 5x

How could I do so that the result on the screen so I left the 3x^2 + 8x

thanks

Richard Morris

unread,
Nov 5, 2013, 5:11:29 AM11/5/13
to jep-...@googlegroups.com
Sorry for the delay in replying.

You can use the class org.lsmp.djep.sjep.PolynomialCreator this converts equations to a polynomial form which can then be fully expanded.

    XJep xj = new XJep();

    PolynomialCreator pc = new PolynomialCreator(xj);

    String eqn = "3(x + 0)(x + 1) + 5(x + 0)";

    Node n1 = xj.parse(eqn);

    Node n2 = pc.expand(n1);

    xj.println(n2);

This works well when the equations you are working with are polynomials. If you have a more general type of equation you can org.lsmp.djep.rewrite.RewriteVisitor but this is less more experimental.

Richard

Andrés Mauricio Barragán Sarmiento

unread,
Nov 21, 2013, 7:57:42 PM11/21/13
to jep-...@googlegroups.com
Hi Richard, thank you very much for your help, and I managed to build the polynomial. Now I have another related pregnta:

When I build a polynomial for example from the following expression:
1.0 + 1.718281828459045(x - 0.0) + 1.4762462210062803(x - 0.0)(x - 1.0) + 0.8455356852954751(x - 0.0)(x - 1.0)(x - 2.0)

When I build it and simplify it is:
1.0 + 1.933106978043715*x +- 1.060360834880145*x^2.0 + 0.8455356852954751*x^3.0

How could I do for me to stay well:
1.0 + 1.933106978043715*x - 1.060360834880145*x^2.0 + 0.8455356852954751*x^3.0

That is, instead of that I see a "+-" left alone "-"

Thank you very much for your help

Richard Morris

unread,
Nov 23, 2013, 7:22:43 AM11/23/13
to jep-...@googlegroups.com
Hi Andrés

This was a bug which was fixed since the Jep 2.4.1 release. It is uploaded to the cvs service but we are not planning a new release on the Jep 2.4 branch. To get the latest version in that branch you will need to download using anonymous cvs http://sourceforge.net/p/jep/cvs/?source=navbar

You may also be able to get the desired results with you current version by using the sjep package. You may find the following works

String s = "1.0 + 1.71(x - 0.0) + 1.47(x - 0.0)(x - 1.0) + 0.84(x - 0.0)(x - 1.0)(x - 2.0)";
Node node = j.parse(s);
PNodeI pnode = pc.createPoly(node);
PNodeI pnode2 = pnode.expand();
System.out.println(pnode2);

Beyond that you can examine the actual date returned pc.createPoly. This gives of the actuall coefficients and you could look at this to dispaly the desired expression.


Hope that helps

Richard

Andrés Mauricio Barragán Sarmiento

unread,
Nov 23, 2013, 1:04:10 PM11/23/13
to jep-...@googlegroups.com
Thank you Richard, I actually managed to solve my problem with this solution you gave me
Reply all
Reply to author
Forward
0 new messages