I'm just being curious about building a CAS (computer algebra system) application in console mode.
It should be able to take a simple algebraic expression like
x+3=56
and then evaluate x as 59.
My ideas were:
1) split into two parts - x+3 and 56.
2) identify the variable (x) and it's modifiers (+3)
3) create an empty string
4) copy '56' into it, and then append '-3'
5) evaluate ("56-3")
so shortly, what would be the best way to go about this?
and if it is TOO DIFFICULT and TROUBLESOME, just tell me, and I will stop thinking about it.
For simple algebraic expression like x+3=56 (symbols, arithmetic operators, paranthesized expressions, mathematical and trigonometric functions etc.), it is fairly straightforward. For instance, it wouldn't take more than a day to write up a Pratt parser to generate the abstract syntax tree which is evaluated using the interpreter pattern.
It gets exponentially heavier as one adds domains - matrices, rationals, complex, differential equations ... And the simple approach above would collapse under the weight.
well for single variable non polynomial equations like you presented is a piece of cake.
first off you need to receive input, a string or array of chars.
then you need to break it down using a custum made parser, thats a program that reads strings and turns it into data.
and lastly its just ordinary arithmetics to solve it.
But if you want a real challenge make a program where
input = N eqations with N variables
and output = the solution to N variables.
ofcoarse if you studied linear algebra then that should guide you, but if you didnt then improvise something, could be great practice.