john ranella

john ranella

  • 1.6k
  • 193
  • 5.8k

Define mathematical expressions at run-time

Oct 5 2015 12:41 PM
Hi,
i need to implement a feature in my program to enable users to defining mathematical expressions.
Suppose we have this class
public class test3
{

public float x = 2;
public float y = 3;
public float z = 0;
public float w = 0;

public double MyEquation()
{
return 0.0F;
}

}


i need to read an external file (txt or xml) that contain string equation, for example (x * x + 0.14 + y)
and replace at run-time the return value of method 'MyEquation' with the new equation

public double MyEquation()
{
return (x * x + 0.14 + y) ;
}



available fields are many (x, y, z, w, k, n, m, j, etc ..) and I can not know how many and what fields the user will use in its expression
there is a way to do this?