Dear all,
I would like to solve a set of linear equations with VBA. I need to do this with VBA, because the number of equations is dynamic.
While executing I get the error as metioned in the title and the last line is highlighted. I read a lot about the error, but I couldn't find my mistake.
Someone who has an idea?
Thanx in advance,
Michael
ps: I'm not sure if it's really necessary to copy all the values in newly defined matrices? Maybe it's possible to work with a command which select the matrix directly from the spreadsheet?
This is the code I made:
I would like to solve a set of linear equations with VBA. I need to do this with VBA, because the number of equations is dynamic.
While executing I get the error as metioned in the title and the last line is highlighted. I read a lot about the error, but I couldn't find my mistake.
Someone who has an idea?
Thanx in advance,
Michael
ps: I'm not sure if it's really necessary to copy all the values in newly defined matrices? Maybe it's possible to work with a command which select the matrix directly from the spreadsheet?
This is the code I made:
Code:
Sub Test()
With Application.WorksheetFunction
Dim N As Integer
N = Range("I2").Value
'Initialize the matrix A
Dim A() As Variant
ReDim A(9 + 2 * N, 9 + 2 * N)
For Index = 0 To 9 + 2 * N
For m = 0 To 9 + 2 * N
A(Index, m) = Cells(97 + i, 58 + m)
Next m
Next Index
'Initialize the rhs of the equations
Dim B() As Variant
ReDim B(9 + 2 * N)
For Index = 0 To 2 * N + 9
B(Index) = Cells(3 + i, 58 + Iteration)
Next Index
'Compute the solution
Dim Corrections As Variant
Corrections = .MMult(.MInverse(A), B)
End With
End Sub