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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Solving a polynomial

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    84
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Exclamation 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).
    please help.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Solving a polynomial

    What have you tried so far?

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    84
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default Re: Solving a polynomial

    Quote Originally Posted by Mr.777 View Post
    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??

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default 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?

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

    arvindbis (March 7th, 2012)

  6. #5
    Member
    Join Date
    Mar 2011
    Posts
    84
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default Re: Solving a polynomial

    Quote Originally Posted by Mr.777 View Post
    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.
    Last edited by arvindbis; March 7th, 2012 at 09:38 AM. Reason: mistyped

  7. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Solving a polynomial

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

  8. #7
    Member
    Join Date
    Mar 2011
    Posts
    84
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default 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!
    awaiting your reply
    thank you
    Last edited by arvindbis; March 7th, 2012 at 11:11 AM.

  9. #8
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default 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.

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

    arvindbis (March 7th, 2012)

  11. #9
    Member
    Join Date
    Mar 2011
    Posts
    84
    My Mood
    Daring
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default 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

  12. #10
    Member
    Join Date
    Feb 2012
    Posts
    106
    My Mood
    Yeehaw
    Thanks
    8
    Thanked 11 Times in 11 Posts

    Default 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

    your string array looks like
    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.
    addition and subtraction, also 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.

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

    arvindbis (March 8th, 2012)

Similar Threads

  1. Polynomial LinkedList from Text File (Modification)
    By javaNewb37 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 27th, 2011, 02:05 AM
  2. Help with Polynomial Graph Plotter and its scaling
    By sojharo in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 23rd, 2011, 06:04 PM
  3. API polynomial java
    By mcherkao in forum Java SE APIs
    Replies: 1
    Last Post: September 10th, 2010, 08:39 AM
  4. Problem in recursion for Solving Maze Recursively program
    By _Coder1985 in forum Algorithms & Recursion
    Replies: 1
    Last Post: April 29th, 2009, 04:37 AM