On 23 Aug 00, at 19:39, crzhang wrote:
> Hi all:
> Now i have a string "3*2*sin2+2*1", i want to get this string's mathematic result,
>but i don't know how to do.Can you help me?
> Best Regards
>
Hmm. This is often covered in higher level programming classes,
especially "compiler design" or "languange design" classes (of
which I have not taken...).
However if all you want is a simple (from left to right) algebraic
solver, then it should flow something like this.
1. Break the string into "tokens" where recursives functions
labeled "istokenA(), istokenB(), etc..." functions are often used to
idetify valid tokens.
2. Next process these "tokens" with a solution engine. When all
tokens are processesed the solution engin will have the result.
In you example string "3*2*sin2+2*1" the token types I would use
are "operators" , "values" and "functions".
Valid operators are <+,-,*,/>
Valid Functions are <cos(x), sin(x), tan(x), sqr(x), sqrt(x), (x)>
(here I added "(x)" as a "function" this is because x could be a
mathmatical string that is processed to a "value" result, which
follows the definition of a function, and the processing engine would
then handle the ordering of execution correctly).
Valid values are all numbers with no letters before or after them (to
seperate a function from a value).
If the solution engine is written correctly you could even add
mathmatical precedents.
Check around on the net, especially "sourceforge.net", for
implemented solutions. Several people have probably solved that
problem already.
Its not to difficult to do a simple one, but adding in functions,
mathmatical precedents, and () operators does tend to make the
coding trickier if you haven't codeded anything like that before (the
trinometric functions (sin/cos/tan) are the hardest to implement if
you don't have a good math library).
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/