Resolver sistemas de ecuaciones por eliminación gaussiana excel

Tengo un código para realizar eliminación gaussiana de sistemas de ecuaciones y requiero aplicarlo en Excel pero presenta fallas

Mis conocimientos de macros son mínimos, me podrían orientar cómo realizar el proceso.

Gracias!

Sub llamar()
Function GaussElim(coeff_matrix, const_vector)
Dim AugMatrix() As Double, ResultVector() As Double
Dim NormFactor As Double
Dim temp As Double, term As Double, ElimFactor As Double
Dim I As Integer, J As Integer, K As Integer
Dim C As Integer, R As Integer
Dim N As Integer

N = coeff_matrix.Rows.Count
ReDim AugMatrix(N, N + 1), ResultVector(N)

For K = 1 To N
'Normalize each row, from column K to right.
'If normalization factor zero, swap rows
NormFactor = AugMatrix(K, K)
If NormFactor = 0 Then
For J = 1 To N + l
temp = AugMatrix(K, J)
AugMatrix(K, J) = AugMatrix(K + 1, J)
AugMatrix(K + 1, J) = temp
Next J
NormFactor = AugMatrix(K, K)
End If
For C = K To N + 1
AugMatrix(K, C) = AugMatrix(K, C) / NormFactor
Next C

'Eliminate
For R = K + 1 To N
ElimFactor = AugMatrix(R, K)
For C = K To N + 1
AugMatrix(R, C) = AugMatrix(R, C) - AugMatrix(K, C) * ElimFactor
Next C
Next R
Next K
'Calculate and return the coefficients.
'Selected range can be either horizontal or vertical.
For K = N To 1 Step -1

ResultVector(K) = AugMatrix(K, N + 1)
term = 0
For C = N To K + 1 Step -1
term = term + AugMatrix(K, C) * ResultVector(C)
Next C
ResultVector(K) = AugMatrix(K, N + 1) - term

Next K
If Range(Application.Caller.Address).Rows.Count > 1 Then
GaussElim = Application.Transpose(ResultVector)
Else
GaussElim = ResultVector
End If
End Function

0

Añade tu respuesta

Haz clic para o