开发者

Write a function to solve a simple linear equation

I开发者_StackOverflow 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.


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

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

For parsing, you could use regular expressions.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜