# Solving a polynomial

• March 7th, 2012, 02:32 AM
arvindbis
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).
• March 7th, 2012, 04:37 AM
Mr.777
Re: Solving a polynomial
What have you tried so far?
• March 7th, 2012, 07:55 AM
arvindbis
Re: Solving a polynomial
Quote:

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??
• March 7th, 2012, 08:18 AM
Mr.777
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?
• March 7th, 2012, 08:31 AM
arvindbis
Re: Solving a polynomial
Quote:

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 :cool:) 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.
• March 7th, 2012, 09:18 AM
Mr.777
Re: Solving a polynomial
Alright.... So, what's the problem in coding all this equation's solution? You almost did that..
• March 7th, 2012, 10:09 AM
arvindbis
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
• March 7th, 2012, 10:20 AM
Mr.777
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.
• March 7th, 2012, 09:35 PM
arvindbis
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
• March 7th, 2012, 11:16 PM
JonLane
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.