469,921 Members | 2,093 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,921 developers. It's quick & easy.

Declare any mathematical equation

Guyz, I really need help on this.

I'm trying to make some mathematical programming.

We can input any equation and then the compiler will detect how many variables was (on the equation). After that, we'll input the variable value to get the final solution.

Example:
Please input an equation,f =
= (x*x)+(4*y)-(4*z*z*z) // ( f ) = x + 4y - 3z = 0

Output:
There were 3 variables = x, y and z. Please insert the value for every variable.
x= 1
y= 2
z= 3

Solution: f = -101

Sorry for my bad english ;-/
Sep 25 '07 #1
3 4955
Meetee
931 Expert Mod 512MB

Example:
Please input an equation,f =
= (x*x)+(4*y)-(4*z*z*z) // ( f ) = x + 4y - 3z = 0

Output:
There were 3 variables = x, y and z. Please insert the value for every variable.
x= 1
y= 2
z= 3

Solution: f = -101
Hi,

It's not tough to solve. You just need to take three variables and one variable for f. and direct put the eqation in code and print f as output.

You need to learn for some basic fundamentals of C++. Also read posting guidelines as we are not allowed to put whole code.

Regards
Sep 25 '07 #2
Hi,

It's not tough to solve. You just need to take three variables and one variable for f. and direct put the eqation in code and print f as output.

You need to learn for some basic fundamentals of C++. Also read posting guidelines as we are not allowed to put whole code.

Regards
Dear sir, actually I just wondering how to write the pseudocode to enable the computer can detect/read variable exist if I type any formula as input.

Example:
Please input any formula for f(x) =
> a + b + c

Output:
There was 3 variables on the formula given, a,b & c.
Please insert the value for a:
>1
Please insert the value for b:
>2
Please insert the value for c:
>3
The answer for f(x) = 8

Appreciate if somebody can solve this matter.
Apr 23 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Use a token parser. As the tokens are extracted from the equation, the ones that are not + - () , etc would be variables. You could then ask for the variable value before evaluating.

Probably you will need syntax to help you.

a + b + c

might have to be entered as

a * a * a + b * b + c

or maybe

a^3 + b^2 + c

for example.

Here if the operands of the * operator are not numbers, they are variables.

I would stick with simple stuff first and then try to generalize it.

You might check out reverse Polish notation and push-down stacks for evaluation.

If you are going to try this in C++ consider a finite state automoton for State machine. There is an article in the C/C++ HowTos on the State design pattern.
Apr 23 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by gelong | last post: by
4 posts views Thread by Xah Lee | last post: by
6 posts views Thread by Trev17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.