+ Reply to Thread
Results 1 to 3 of 3

Get to the General Formula of an Equation

  1. #1
    Registered User
    Join Date
    04-14-2013
    Location
    Mexico
    MS-Off Ver
    Excel 2010
    Posts
    2

    Get to the General Formula of an Equation

    Im trying to make a macro that will multiply any matrix by another one, and ive succeded in doing it when i know the range of the matrix but i dont know how to make it work for any given matrix without having to change my i and j counter and as long as the number of rows in the first one is the same as columns in the second one, here is what i have:

    Sub MultMatrices()

    For i = 1 To 8
    For j = 1 To 8
    suma = 0
    For k = 1 To 8
    suma = suma + Worksheets("hoja1").Cells(i, k).Value * Worksheets("hoja2").Cells(k, j).Value
    Next k
    Worksheets("hoja3").Cells(i, j).Value = suma
    Next j
    Next i

    End Sub

  2. #2
    Registered User
    Join Date
    04-14-2013
    Location
    Mexico
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Get to the General Formula of an Equation

    sorry for my english, im not a native speaker, if there is a redaction problem, ask me and i will try to explain myself better

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Get to the General Formula of an Equation

    This forum is pretty strict about enclosing code in code tags. Instructions for using code tags are in the forum rules link at the top of the page.

    Does this have to be VBA? My first thought is to use the MMULT() function. http://office.microsoft.com/en-us/ma...859.aspx?CTT=1
    Your title suggests that this might be regression problem. You might look at the LINEST() function http://office.microsoft.com/en-us/ex...005209155.aspx
    If it does nned to be VBA, you these functions are available in VBA http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx

    ive succeded in doing it when i know the range of the matrix but i dont know how to make it work for any given matrix without having to change my i and j counter and as long as the number of rows in the first one is the same as columns in the second one, here is what i have:
    One of the basic programming skills (independent of programming language) is the ability to break a task down into manageable steps. I don't know all of your requirements and expectations for this procedure. I would start solving this problem by considering how you solve it in your head when you know the ranges of the matrices. I suspect it looks something like this:

    1) Identify the matrices (you might use the Set statement for this)
    2) count the number of rows and/or columns in each matrix and assign to a variable (range.rows.count might work for this)
    3) check for columns of first matrix = rows of 2nd matrix
    4) perform multiplication
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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