+ Reply to Thread
Results 1 to 9 of 9

Program to establish a matrix

  1. #1
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146

    Program to establish a matrix

    I need to establish a matrix of "n"s and I'm hoping to figure out a programmatic way of doing so. The matrix is defined by the following:

    z = abs(n1) + abs(n2) + abs(n3) ....
    where z is user generated value between 3 and 31 and n# can range from 2 to 100 (again user specified).

    For example if z=3 and n3 is the max value the first few entries will be:

    -3 0 0
    -2 -1 0
    -2 0 -1
    -2 0 1
    -2 1 0
    -1 -1 -1
    -1 -1 1
    etc

    Does anyone have any ideas on how to approach this beast? For now it can just be stored starting in sheet1 range a1 with z and n# specified in the program.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Program to establish a matrix

    I don't understand ...
    z = abs(n1) + abs(n2) + abs(n3) ....
    where z is user generated value between 3 and 31
    How are those two statements consistent?

    How did you generate your example?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146

    Re: Program to establish a matrix

    "Matrix" was a bad word choice. The proper phrase is a series of simultaneous equations. So going to my example it would look like this:

    -3 0 0
    -2 -1 0
    -2 0 -1
    -2 0 1
    -2 1 0
    -1 -1 -1
    -1 -1 1
    etc

    is derived from:
    3= abs(-3) + abs(0) + abs(0)
    3= abs(-2) + abs(-1) + abs(0)
    3= abs(-2) + abs(0) + abs(-1)
    3= abs(-2) + abs(0) + abs(1)
    3=abs(-2) + abs(1) + abs(0)
    3=abs(-1) + abs(-1) + abs(-1)
    3=abs(-1) + abs(-1) + abs(1)
    etc (this example will yield 38 equations)

    The values from these equations will ultimately be used in the equation:
    X(i) = A*n1 + B*n2 + C*n3 ...

    The order of the equations doesn't matter as long as they are all there. Does that make enough sense?
    Last edited by wilro85; 06-26-2009 at 11:33 AM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Program to establish a matrix

    I'm only guessing -- is this the correct output for N=3? Each row sums, in absolute value, to 3.
    Please Login or Register  to view this content.
    Last edited by shg; 06-26-2009 at 07:31 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Program to establish a matrix

    Assuming that's correct, then the number of combinations by value of n is:
    Please Login or Register  to view this content.
    (See http://www.research.att.com/~njas/se...lish&go=Search)

    It gets out of hand pretty quickly. You could list n=7 in versions of Excel up to 2003, and n=9 in Excel 2007. N=31 would require more disk storage than has been manufactured.

  6. #6
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146

    Re: Program to establish a matrix

    Yes, those 38 equations were correct. I didn't think it would get quite that out of hand. Oh well back to the drawing board.

  7. #7
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146

    Re: Program to establish a matrix

    Alright, after a while of having this on the blackboard I've got another way of doing this, but I need a smaller matrix. The attached workbook has the positive half of the third, fourth, and fifth order matrices (if you compare my 3rd order to the one SHG posted in this thread, you'll see my equations are the bottom 19 of his 38. I only need half as the other half can be generated by multiplying by -1).

    So ultimately, I'd like to have a program that can write a matrix of any order starting at a cell that I designate. I can create the matrices by hand, but it is tedious and I'd like to not have to store them all if possible.

    If you're good at loops, see if you can come up with something.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146

    Re: Program to establish a matrix

    Nevermind. I've got something that will work for me.

    Sub EstMat()
    'Sub EstMat(C, R, order)

    Dim x As Integer, y As Integer, order As Integer

    C = 16
    R = 2
    order = 3

    For i = -order To order

    For j = -order To order

    For k = -order To order
    If (Abs(i) + Abs(j) + Abs(k) = order) Then
    Cells(r, C).Value = i
    Cells(r, C + 1).Value = j
    Cells(r, C + 2).Value = k
    r = r + 1
    End If
    Next

    Next

    Next
    End Sub

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Program to establish a matrix

    Please change the QUOTE tags to CODE tags.

    Also, isn't you code correct only for order = 3? I thought there was n1, n2, ..., norder
    Last edited by shg; 07-29-2009 at 09:19 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1