Solves a system of linear equations.
MatrixObject.Solve(RightHandTerms) MatrixObject.SolveGauss(RightHandTerms)
A reference to a one-column matrix containing the solution of the system of simultaneous equations.
MatrixObject must contain the terms of the unknowns of the equations.
Solve method uses matrix inversion and multiplication in order to solve the system of equations. This can be slow for large matrices. As an alternative, you can use the SolveGauss method, which uses Gauss elimination in order to compute the solutions.
Error 1305 will be returned if the matrix is not square.
Error 1310 will be returned if if the system of simultaneous equations cannot be solved (equations are inconsistent).
This example demonstrates the use of the Solve method.
Private Sub MatrixSolve()
Dim A As Matrix, RH As Matrix, S As Matrix
Debug.Print "System of linear equations to be solved"
Debug.Print " x + 2*y + 1*z = 1"
Debug.Print "2*x + 3*y + 4*z = 2"
Debug.Print "3*x + 2*y + 1*z = 2"
Debug.Print
'Matrix A will contain the coefficients of the unknowns'
Set A = New Matrix
A.Size 3, 3
A(0, 0) = 1: A(0, 1) = 2: A(0, 2) = 1
A(1, 0) = 2: A(1, 1) = 3: A(1, 2) = 4
A(2, 0) = 3: A(2, 1) = 2: A(2, 2) = 1
'Matrix RH will contain the right hand terms of equations
Set RH = New Matrix
RH.Size 3, 1
RH(0, 0) = 1
RH(1, 0) = 2
RH(2, 0) = 2
'Matrix S will contain the solution
Set S = A.Solve(RH)
Debug.Print "Solution :"
Debug.Print "x ="; S(0, 0); ", ";
Debug.Print "y ="; S(1, 0); ", ";
Debug.Print "z ="; S(2, 0)
End Sub
System of linear equations to be solved x + 2*y + 1*z = 1 2*x + 3*y + 4*z = 2 3*x + 2*y + 1*z = 2 Solution : x = 0.5 , y = 0.2 , z = 0.1