Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Solving a polynomial

I seeking to have some ideas in order to solve polynomial equations like 5x2+3x-8where x=7, then we can substitute this value of x in the given equation and can find the total value to which can be evaluated e.g. the above equation can be calcutaled as 258, also able to solve equations with two variables.
note: polynomial equation will be provided as string!(as user input).  Reply With Quote

3. ## Re: Solving a polynomial

What have you tried so far?  Reply With Quote

4. ## Re: Solving a polynomial Originally Posted by Mr.777 What have you tried so far?
very good question, indeed. I'm not able to think how to convert a full equation variables into system variables??  Reply With Quote

5. ## Re: Solving a polynomial

Take a copy and pen, write down the steps of solving the thing. Start coding. If you get stuck, ask here.
Can you tell me by the way, how the above equation will be calculated to 258?  Reply With Quote

6. ## The Following User Says Thank You to Mr.777 For This Useful Post:

arvindbis (March 7th, 2012)

7. ## Re: Solving a polynomial Originally Posted by Mr.777 Can you tell me by the way, how the above equation will be calculated to 258?
Note:wesolution is in reference to equation in first post in this thread.
there value of x is 7(already given i'm damn good at these ) just put this value of x, then equation will become 5*(square of 7 i.e.pow(7,2))+3*7-8 and result will amount to 258.
where 5x2 stands for 5times the square of x.  Reply With Quote

8. ## Re: Solving a polynomial

Alright.... So, what's the problem in coding all this equation's solution? You almost did that..  Reply With Quote

9. ## Re: Solving a polynomial

problem is that equations will be much more complex like 7x4y2z3+78xz+....you can't expect how many variable it may have as it deepends only on user input.
and secondly these equations are feeded as string.
from above i can conclude that my problem is how to repsent equations in java??
I had implemented in c and c++ as there I can use pionter arthmatics using Dynamic-linked-list while jvm is mangaing pointer here. I think you understood what I'm looking!
thank you  Reply With Quote

10. ## Re: Solving a polynomial

Well, i can tell you one thing. Extract the unique alphabets from the given String, Get user values for those unique alphabets(whatever you call them in Mathematics, i guess variables), start searching the String, replace the alphabets with the values, equate them and get your answer.  Reply With Quote

11. ## The Following User Says Thank You to Mr.777 For This Useful Post:

arvindbis (March 7th, 2012)

12. ## Re: Solving a polynomial

good idea still how to get the power system to work as you suggested( i really liked the idea). I tried it but still one problem is that term of equation "5x2" means 5 times square of x that means even if I'm able to replace the variable with value it may not give correct answers for equation of higher degrees like having terms x2, x3...etc  Reply With Quote

13. ## Re: Solving a polynomial

Get the String:
String equation = user input;

Separate the string into a String list(array? arrayList?) of components.

example
equation = x^7+13x^4-22

string1 = x^7
string2 = +
string3 = 13x^4 (not sure if you need 13(x^4) to be specific
string4 = -
string5 = 22

remember multiplication and division are commutative.

on a side note ^ (shift6) is used to show something raised to the power of. x^2 is x squared 3^3 is 27
thus, to be a stickler what you want is:

5(x^2)+3x-8

once you have the equation broken into logical usable parts what you do with it is all mathematical logic. I would suggest recursion but it would probably only add a layer of complication if you are not good with recursive coding.

but if you find you have just an x value and a constant, then you can solve by isolating x. if you have an x^2 and an x and a constant to can solve using standard binomial methods. Write methods to solve the equation based on what type it is.  Reply With Quote

14. ## The Following User Says Thank You to JonLane For This Useful Post:

arvindbis (March 8th, 2012)