how can I read any function given by user

Actually I need such a program in c, where, in the input screen if I give the function, and any point where I need the functional value , the program identify the function and gives me the functional value.

such as,
If , as input I gave
f(x)=X^2+sin(x)+e^x
and gave x=1
then the in the output screen I get f(1)=1+sin(1)+e

Hi,

Actually computing the function value from the input expression would fall in the ambit of symbolic mathematics, which, I believe is strongly connected to string parsing in a more beginning state.

So, I think that your problem can be reduced to a “simple” string processing problem.

You should keep a table of symbols which stand for the common operations, like +,/,x,^, etc and then you must try and play with it a bit…

Like, if you find a ^ you must convert the base and exp to numbers to display the result, you should keep constants unchanged, if you find a parenthesis, then you know you have a function. Then you:

a) Either reduce the argument if its an expression f(x^2 + 6) reduces to f(result);

b) Leave it as it is replacing x by the value given;

I know this sounds easier said than done, but, while the code might be hard to get working properly, I believe this is the whole idea :slight_smile:

Best,

Bruno

1 Like
//