0

Lets assume I have a UI box where the use can type an equation as a string format :

    y=f(x) for example y=x*x, y=exp(x), etc ...

I want to draw that function. At compile time I just know that the variables used will be x and y. Is there a way to transform the string "y=x*x" to a mathematical equation that I can treat to calculate the values?
I know that C++ produces compiled code but I would like to know whether or not there is a way to do that in C++? If not, what would be an alterntive to mix C++ with, to get that done?
Cheers

DarkVapor
  • 61
  • 6
  • "I want to draw that function", Very baffling... Do you want to put a graph in c++? – Irrational Person Feb 17 '15 at 22:07
  • 1
    Yep, that is possible. But if you want to do it by hand, this is too broad. If you are looking for a library that does it, it is OT because rules. Search the internet for something like *"C++ parse math equation"*. – Baum mit Augen Feb 17 '15 at 22:07
  • @IrrationalPerson It’s standard calculus parlance … maybe not exact but common. – Konrad Rudolph Feb 17 '15 at 22:08
  • possible duplicate of [How to draw functions in C++](http://stackoverflow.com/questions/15985118/how-to-draw-functions-in-c) – Axalo Feb 17 '15 at 22:10
  • @Axalo not really, that one's about drawing a function. This one really has more to do with creating a function out of user input. – genisage Feb 17 '15 at 22:11
  • @Baum : I found that : http://www.codeproject.com/Articles/7773/Fast-Mathematical-Expressions-Parser which looks interesting. – DarkVapor Feb 17 '15 at 22:18
  • @user3657588 See what a nice search engine can do for you! :) Yes, there a plenty of free libraries online, just look around and pick whatever suits your needs best. (And read the license if you are going to distribute your stuff ofc.) – Baum mit Augen Feb 17 '15 at 22:22
  • @Baum : thanks for your help :) Didn't expect that I would need to use a library for that though .... – DarkVapor Feb 17 '15 at 22:23
  • @user3657588 You can of course write your own stuff for that (for fun). But if you don't need to, don't. Much evil in this world comes from that. – Baum mit Augen Feb 17 '15 at 22:24
  • @Baum : Yes, However, I would be interested in the main "idea" to be able to write such a parser. – DarkVapor Feb 17 '15 at 22:26
  • @user3657588 Your favorite search engine -> http://stackoverflow.com/questions/114586/smart-design-of-a-math-parser – Baum mit Augen Feb 17 '15 at 22:29

0 Answers0