# solving 9 equations 9 unknowns in vba

1. ## solving 9 equations 9 unknowns in vba

hi
solving 9 equations 9 unknowns in vba With the following conditions:
Example
a11X1 +a12X2+……+a19X9 = b1
a21X1 +a22X2+……+a29X9 = b2
. . . . . . . . . . . . .
a91X1 +a92X2+……+a99X9 = b9
in Sheet 1
a11 in Cell A1 and a12 in Cell B1 ...
a21 in Cell A2 and a22 in Cell B2 ...
.....
.....

in Sheet 2

b1 in Cell A1
b2 in Cell A2
.....
.....

in Sheet 3
(An important part of my question)
solving 9 equations 9 unknowns Without using any formula, just press a button key(vba code)
---------------------------------------------
Can someone help me,Tanks

2. ## Re: solving 9 equations 9 unknowns in vba

As this kind of has the feel of a homework problem, I don't want to give away too much and short circuit what you are supposed to learn from the exercise. On the other hand, I'm not certain what skills you are supposed to be learning from this.

A few questions/observations before we delve into programming the solution.

1) I find that I first need to understand the math behind a problem. Here's a tutorial on solving systems of linear equations: http://www.purplemath.com/modules/systlin6.htm Her tutorial focuses on the simpler 2 and 3 variable cases, but the concepts extend to 9 variables without modification. Wikipedia's page http://en.wikipedia.org/wiki/System_of_linear_equations may be useful because it has a section specifically discussing this in terms of matrix algebra.

2) If you are going to use matrix algebra to solve these systems of equations (which ultimately leads to the question of how to code inverting a matrix), the next question will be about using Excel's built in MINVERSE() function. You've indicated that you cannot use the any worksheet function in the spreadsheet, are you likewise not allowed to call worksheet functions from VBA? If you are allowed to call Excel functions from VBA, then that becomes the heart of the problem http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx If you are not allowed to call worksheet functions from VBA, then this becomes the more difficult problem of coding matrix inversion/Gaussian elimination. If this is about coding a matrix inversion algorithm from scratch, you will probably have to remind those of us who have not had to bother with this kind of coding for a long time exactly what that entails, so we can help you put those steps into VB/VBA specific syntax.

3) Or perhaps you want to use something more like root finding algorithms (newton raphson for example) to solve these. As Excel already has the NR algorithm in the Solver utility, we will need to know if you are allowed to use the Solver utility or if you need to code your own NR/iterative algorithm. If you are allowed to use Solver, then this is mostly about how to call Solver from VBA (if you search, we already have many examples of how to do that). If you are not allowed to use Solver and you need to code an NR type algorithm from scratch, then, again, you will probably need to remind those of us who haven't had to do this for a long time of some of the detail of such a coding exercise, then we will better be able to help you put the algorithm into VBA specific syntax.

3. ## Re: solving 9 equations 9 unknowns in vba

see attached example for 2 equations

4. ## Re: solving 9 equations 9 unknowns in vba

just for interest, and for the record

gauss-jordan matrix inversion

put a square nonsingular matrix - any size - in the current region of Range("A1"), and run the code

linear equation solution is easy extension, although not really necessary to do the full inversion if equation solution is all that's needed
``Please Login or Register  to view this content.``

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

#### 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