Wednesday - borland c ++ builder 6. In general, my goal is that the user enters a function, and the program builds its schedule. How to build a graph and find the values ​​of the function I know about. The problem is: how do we get a function from edita to work with it. After all, we get a string, but how to substitute values ​​into it and generally work with it?

  • There are whole math packages like mapple. How close do you want to get close to them? It may be worthwhile to implement several options, and then think about the parser of arbitrary functions, since You will definitely meet with all sorts of "jokes", for example, break points. - LXA
  • @LXA what are the packages? And what is the problem of break points, the cycle will simply iterate over the values ​​in a given interval and build a graph on them - Nik Haker
  • Already mentioned Maple, as well as Wolfram Mathematica, Maxima. Special points will need to be searched automatically and processed specifically. Far from all functions will obey your assumption of smoothness, continuity, therefore it is impossible to use equal intervals on the x-axis. - LXA

2 answers 2

  1. Parse the string
  2. Build an expression tree
  3. You execute a tree, substituting the necessary variables
  4. Draw the result

Example (simple, but contains errors)

  • But after all the functions are innumerable, is this the infinite expression tree going to be chtoli? - Nik Haker
  • @NikHaker, you only parse one line - and get only one tree - Grundy
  • @Grundy One line can contain a huge number of options. Or I did not understand correctly, explain a little more about the tree - Nik Haker
  • @NikHaker, for mathematical expressions, you do not need to build a tree, see the links I gave in the comments to the post - Grundy

As I understand it, a parser is needed. Check out Qt Qt and QScriptEngine Engine.

  • Is this already a new language? - Nik Haker
  • This is a scripting language. The script is embedded in the code and interpreted using QScriptEngine. I can not boast of experience with this. But here is a good article link . Here it is clear that special study of syntax is practically not required. Either do as described zenden2k and Grundy, but then all handles - StrangeOwl