Search code examples
functionmathcalculus

implementation of the calculus functions i.e f(x), in programming


I want to write a program that calculates a given math function (by the user) with specific set of values.

The user is asked to type a function, say he typed f(x)= (x^2)+3x+1 then through the program I should show the outputs of [ f(3), f(6) and f(9) ] .

The question specifically is how to fetch these x's in the typed function, then how to convert the function from a string to a double or float.

Do you have any thoughts about that ?

suppose that I'm using C , or C++


Solution

  • This is not an easy task, especially as operators hold precedence over others.

    Have a look at some of these links so see what you're dealing with:

    Equation (expression) parser with precedence?

    http://en.wikipedia.org/wiki/Operator-precedence_parser