Jump to content

symbolic equation solving?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Witash

Witash

    Newbie

  • Members
  • Pip
  • 3 posts
I have been trying to write a program that symbolically solves simple algebraic equations. What I have now works fine, except when there is more than one instance of the variable that is being solved for. I cannot figure out how to combine variables. So my question is, is there an algorithm for symbolically solving equations available somewhere, and I just can't find it? Or do I have to keep banging my head against the wall?

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Hello Witash, can you post the bit of code that you have in question?

#3
Witash

Witash

    Newbie

  • Members
  • Pip
  • 3 posts
Well, I don't have much code at this point; i am still trying to work out an algorithm. Here is what i have so far in pseudocode:

to solve for x in an equation
split the equation into side1 and side2
while side1 != x

nextop=next operation* of side1
split side1 into leftside and rightside, based on the position of the next operation
if x is ONLY in leftside

side1=leftside
side2=side2+the opposite of nextop+rightside

else if x is ONLY in rightside

if nextop== - or /

side1=rightside
side2=leftside + nextop + side2

else

side1=leftside
side2=side2 + the opposite of nextop+ rightside

end if

else if x is in BOTH SIDES

????combine the two sides????

end if

end loop

This will work as long as there is only one instance of x. But, I haven't been able to figure out how to combine the two sides if there is more than one instance of x. So, for example, y=2*x would work fine, and give you x=y/2. but y=x+x would not work with this method. in this case x+x needs to be combined into 2*x before the loop can continue, and that's the part i can't figure out.

*I didnt include how to find the next operation here to try to keep this short. I'm completely sure it works as designed though.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Depending on the language you are working with, it might be worth-while to try to create some classes for handling expressions. Then you could work out how to perform certain types of expressions as a sort of library.

I've thought about this sort of thing in the past (I was planning to make Java applets as a tutoring tool for students). If you can create classes for rational numbers, linear expressions, polynomials, etc, then you can define how to add, subtract, multiply, divide them. At that point, the x + x situation becomes an issue of an unsimplified linear expression and the class will handle it for you.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Witash

Witash

    Newbie

  • Members
  • Pip
  • 3 posts
Thanks wingedpanther, i think that is probably the best way to do it, especially since i intend to use Java. From what I can see, It's still going to be complicated , but i agree that using classes will make it much more manageable.