Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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++

like image 477
Fahd Avatar asked Aug 08 '11 00:08

Fahd


1 Answers

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

like image 94
Griffin Avatar answered Oct 06 '22 01:10

Griffin