1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ implement polynom

  1. Jan 23, 2012 #1
    Hi,
    I need to implement polynoms in c++.
    I thought of doing this with lined list,i am not alowed using c++ linked list, so i will built it myself.
    I started thinking of adding and substructing,
    should i first sort the polynoms i want to sum by its exponents? (in this case it will be easerear to compare between 2 exponents),
    or is there a way doing the adding without sorting?...

    Thanks!
     
  2. jcsd
  3. Jan 23, 2012 #2

    jedishrfu

    Staff: Mentor

    Try using a simple array of double with the index being the power.
     
  4. Jan 23, 2012 #3
    The instructions were to use a linked list...
     
  5. Jan 23, 2012 #4

    jedishrfu

    Staff: Mentor

    Sorry I saw your comment that said you weren't allowed to use a linked list I took to mean you weren't allowed to write one either.

    Okay so write one with content of the node containing the term factor and the power of the independent variable. Add nodes to the list in the order of the polynomial from x0 to xn.
     
  6. Jan 23, 2012 #5
    In order to make the adding easier i need to save the polynom in this order right?
    so if i need to add to a given polynom another node (with new coefficient and exponent) i nedd to insert it on the right place?
     
  7. Jan 23, 2012 #6

    jedishrfu

    Staff: Mentor

    Yes by preserving the order you easily print or compare or evaluate a polynomial. If you want to add two polynomials together you'd create a new polynomial by merging the two.

    You might also wan to put in zero terms as well as placeholders for future manipulation of the polynomial but that's not necessary. Zero term is like x0 + 0x1 + 3x2 ... For 3x^2 + 1
     
  8. Jan 23, 2012 #7
    Ok,
    Many Thanks!!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: C++ implement polynom
  1. LUT implementation (Replies: 1)

Loading...