Variable Substitution

24 views
Skip to first unread message

Alexander Tkachuk

unread,
Aug 5, 2009, 11:11:07 AM8/5/09
to Jep Java Users
Hello,

Just curious, is it possible to do simple and nice with JEP or XJEP
variable substitution. I have multi-steps calculation process, for
example, I have simplest expression x+y+z. On the first step I have
defined x=2, and I would like to reduce or simplify expression to 2+y
+z; on the next step y=3, and I would like to see 2+3+z or 5+z (what
easily can be done by simplification routine from XJEP), and so on. Do
you have any special methods to do that, or it should be done manually
by 'getVarsInEquation' and 'substitute' methods?

Thank you in advance,

Alex

Richard Morris

unread,
Aug 17, 2009, 5:15:55 AM8/17/09
to jep-...@googlegroups.com

Dear Alex,
Sorry for not getting back sooner.

Probably the easiest way to do this is to use the SubstitutionVisitor
and there is a method where you can substitute an equation of the form
"x=2" into another.

For example you can do
Node eqn1 = jep.parse("x=2");
Node eqn2 = jep.parse("y=3");
Node eqn3 = jep.parse("x+y+z");
SubstitutionVisitor sv = new SubstitutionVisitor(jep);

eqn3 = sv.substitute(eqn3,eqn1); // 2+y+z
eqn3 = sv.substitute(eqn3,eqn1); // 2+3+z

Rich

--
Richard Morris
Web: www.singsurf.org www.pfaf.org
Email: ri...@singsurf.org
Tel: (+44) 01208 872963
Post: 1 Lerryn View, Lerryn, Lostwithiel, Cornwall, PL22 0QJ

Reply all
Reply to author
Forward
0 new messages