in reply to solving multistep equations
Welcome to PerlMonks! Writing an equation solver is a great way to learn (Perl) programming.
To get help with your code, please post it! See this node for information on how to help us help you.
How you approach the problem in general will depend on which level you want to begin.
The basic approach to this kind of problem is to parse the expression using a parser such as a Recursive descent parser to translate the string "197 = 5(4a + 10) + 4a" into a representation that the software can more easily understand and manipulate. The Perl module Parse::RecDescent can help you write such a parser; this might help get you started.
If you don't want to go to that low of a level, it looks like someone else has already written a parser, Math::Expr (haven't used this myself, YMMV). You could use this module to parse the equation, and then manipulate the resulting tree to solve your equation.
Of course, this wheel has already been invented too - a quick search brings up Math::Algebra::Symbols, among others, which can solve equations for you.
And going even further than that, there are full-featured math software packages available for free online, such as Sage online at https://cloud.sagemath.com/ , see in particular this tutorial: http://www.sagemath.org/doc/tutorial/tour_algebra.html . There's also Wolfram Alpha, see e.g. http://www.wolframalpha.com/examples/Algebra.html . If you want a software you can download and install, there's Maxima (I've found wxMaxima a useful interface).
See also a few other places this kind of question has been asked before: Parsing Math Strings, Perl and maths.
|
|---|