Thread: how get an equation ?

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    183

    Question how get an equation ?

    hello .
    I have to write a program that must take an equation from user and then give the answer .
    for example it must take --> ( cosx+1-x=0 ) then give the answer --> 1.2786 .
    I know how to reach the answer but
    I dont know how to get the equation . if I put it in a string then what I must do to tell to the program that the string is a math formula and for example ---> c o s x is cos x and .....?

    hope I could tell my meaning well .

    tnx .

  2. #2
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    there are many algorithms for doing this, I remember implementing a simple scripting language a while back using one of those to parse arithmetic expressions, it's called the shunting yard algorithm, not that hard to implement, but you need to be familiar with stacks

    EDIT:
    check out this site:
    http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm
    for algorithm description and pseudo code.
    Last edited by glUser3f; 01-15-2004 at 09:18 AM.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Use a two-step format:
    1) parse the equation to figure out the operators (+-*/) and operands, and put them in a buffer to calculate later. Look up an algorithm for Reverse Polish Notation.
    2) process the new buffer to arrive at the answer.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    183
    tnx alot .
    but I need more help plz .
    my english isn't good and I dont undrestand the parsing algorythm explanation .

    I have written a program that turns an infix sentence to postfix(suffix) form of it some months ago . but the out put is an string too . what can I do ?
    tnx again for helping .

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    You'll have to explain what you have better than that. What output is a string?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help needed! Finding Root of an Equation?
    By reader in forum C Programming
    Replies: 4
    Last Post: 06-13-2008, 10:10 AM
  2. Replies: 15
    Last Post: 11-04-2006, 04:06 AM
  3. IDEA: Equation solver
    By Magos in forum Contests Board
    Replies: 2
    Last Post: 01-07-2003, 11:46 AM
  4. Quadratic Equation Program
    By Ambizzy in forum C Programming
    Replies: 4
    Last Post: 02-19-2002, 09:21 PM
  5. equation solving
    By ajlott_coder in forum C Programming
    Replies: 6
    Last Post: 01-26-2002, 02:34 AM