matrix formulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sheff
    New Member
    • May 2010
    • 21

    #1

    matrix formulation

    Hi everybody,

    I have polynominal, F = 1+2x+3x^24x^3+5 x^4+6x^5+7x^6 that I would luv to put in matrix form that is shown below


    [7 0 0 0 ]
    [6 7 0 0 ]
    H= [ 5 6 7 0 ]
    [ 4 5 6 7 ]
    [ 3 4 5 6 ]
    [ 2 3 4 5 ]
    [ 1 2 3 4 ]

    plse note the relationship between the polynominal F and matrix H, in the first row of matrix H, we only start with the hight coefficient of the highest degree and we start adding the following coefficients of the lower degree as we go down the rows, I am trying to do that using C , the program I want to do must be general and can be used for different polynominals with different degrees, , I need to do a program that only needs the coefficients of the polynominal and it stright away finds the H matrix I dont need to change anythign manually ,any suggestions of how this can be done please?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Use an array.

    Element 0 for the coefficient of x^0
    Element 1 for the coefficient of x^1
    etc...

    Create the array dynamically when the user specifies the maximum degree of the polynomials to be processed.

    Use an array for each polynomial.

    Comment

    • sheff
      New Member
      • May 2010
      • 21

      #3
      Hi weaknessforcats , thank you for your reply, I did not get what you mean, can you make that a bit more clear please?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Suppose you have 4x^2 + 2x -10.

        Your array is:

        Code:
        int poly1[3] = {-10, 2, 4};
        Suppose you need to multiply this polynomial by 2x+4 then tou have another array:

        Code:
        int poly2[3] = {0,2 4};
        There is no x^2 so I have used a 0 coefficient to keep the arrays the same size.

        The product will have terms up to x^3, so I create the product array;

        int prod[4] = {0,0,0,0};

        4x^2 + 2x -10.
        2x+4

        Now use a loop to multiply every term of 4x^2 + 2x -10 by 2x:

        2 * 4 = 8
        x^2 * x = x^3

        Therefore, ADD 8 to element 3 of the prod array. In code that looks like:

        Code:
        prod[3] += poly1[2] * poly2[1];
        Then repeat the loop multiplying every term of
        4x^2 + 2x -10 by 4.

        The array element position corresponds to the power of the variable.

        Comment

        • sheff
          New Member
          • May 2010
          • 21

          #5
          Hi again, thank you for your reply, I think you miss-understood me, I am doing any multiplication here, all what I need is to formulate the matrix H based on the entries of the polynominal F. just check the relationship between F and H , you will find that the first row of H is filled with the highest value of F, and the lower rows gets the lower value of F and so on, I want to do this using a program in C. there is not any kind of multiplication in here.

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            I was attempting to show how to use an ordered array to represent a polynomial. I was using multiplication as an example.

            This maxtrix:

            H= [ 5 6 7 0 ]
            [ 4 5 6 7 ]
            [ 3 4 5 6 ]
            [ 2 3 4 5 ]
            [ 1 2 3 4 ]

            can be obtain from this array:

            int array[8] = {1,2,3,4,5,6,7, 0};

            [1 2 3 4] is array[0] through array[3]
            [2 3 4 5] is array[1] through array[4]
            [3 4 5 6] is array[2] through array[5]
            etc...

            It shouldn't take much work to parse the array. All you are doing is extracting ranges of values where there is a correlation between the offset into the array and the row of the H matrix.

            Comment

            Working...