views:

57

answers:

2

I need to know how to write a function to solve a simple linear equation like 2x +1 = 5. How would one do this? If anyone can show some code or point me to a site, it would be much appreciated.

+1  A: 

How is the equation enterd? In text-form? As coefficients?

ax + b = c of course has the solution x = (c - b) / a.

For parsing, you could use regular expressions.

Dario
I want to be able to enter it as `2x +1 = 5` then have the function return `x = 2`
agentbanks217
+1  A: 

Parse the expression into a simple tree, then use basic math to solve it. I'd start by converting it to postfix notation and then evaluating that.

Jim Brissom