# Thread: Entering a user equation to a source function ?

1. ## Entering a user equation to a source function ?

Good day and thanks in advance for any help and ideas with my question...

I am a newbie programmer primarily interested in writing simple numerical integrators and root finders and evaluators...

Such as, Euler's Method for approximating integrals and Newton's method for finding roots...Horner's Method for evaluating a polynomail....

So I have some books on the topic of writing the code for the functions (class objects)
which assume that the source function is provided.

Is there a way to have the user input an equation and store it as a string or other, and have that string converted into code ?

I suppose there must be since matlab and others have a way of doing it....
I can only hope that it is not too outside of my understanding..

peace
dpc

2. Parsing equations and formulae like "y=x+1" is very difficult, assuming that's what you mean. Very difficult. I don't think you would be up to the task . . . I'm not sure I would be, especially if I only had a few days to do it.

I have a few suggestions: you could try to find a library that will do this for you. I don't know of any offhand, but I'm sure they exist. Even if you did, however, it would require some degree of programming skill to get them working -- have you ever used external libraries before?

Or you could take up another programming language . . . in Perl, for example, you can do this sort of thing quite easily. C++ simply isn't designed to do this.

3. Hi,

I have not used external libraries before, although that is something I would like to practice..
I'm only working on this for my own edification btw, not home work .. luckily...

Can you suggest some good places to start looking for useful analysis orientated libraries ?

Parsing is what I want to do....doesn't have to be y=x^2, just the x^2 would do...

thanks,
d

4. Parsing is what I want to do....doesn't have to be y=x^2, just the x^2 would do.
If you want to evaluate an expression (instead of solve an equation), then check out the shunting yard algorithm by searching the Web.

5. I will check it out...

Just to clarify.....by evaluating an expression many times, then aggregating the sum, I can integrate and thus numerically 'solve' an equation (especially if it is converging on a constant solution)....such as a first order differential equation.

thanks

d

6. Originally Posted by dcuneo
Is there a way to have the user input an equation and store it as a string or other, and have that string converted into code ?
Just yesterday I was googling about binary trees, when I read that one of their application is right about expressions parsing.
To give you a simple example, the expression A + B * C will be stored this way:
Code:
```    +
/ \
A   *
/ \
B   C```
If you want more go here:
http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Tree/

Wikipedia offers a good start point about binary trees (if you don't know what they are)
good luck