S
souravroy1
Hi all,
I am trying to write a program wich accepts to two arrays one of
coefficients and other of constants and solve it through Gauss
eliminatiion method, the function directly writes the solution in a
colum starting from the given cell
I am not able to trace the problem with the code. though I am new to
excel programming
Can someone help me
The code is as follows:-
Option Base 1
Sub solution(coefficient As Range, constants As Range, output As Range)
p = coefficient.Rows.Count
n = coefficient.coloums.Count
MsgBox ("HI")
Dim a(), R(), sol()
For v = 1 To p
For j = 1 To n
a(v, j) = coefficient(v, j).Value
Next j
R(v) = constants(v).Value
Next v
For i = 1 To n
check = 0
For j = 1 To n
If Not (a(i, j) = 0) Then check = 1
Next j
If check = 0 Then Count = Count + 1
If Not (R(i) = 0) Then
For d = 1 To n
e = a(i, d)
a(i, d) = a((p - Count), d)
a((p - Count), d) = e
Next d
End If
For k = 1 To i
For l = 1 To (i - 1)
coef = a(i, l)
For m = 1 To n
a(i, m) = a(i, m) - (coef * a(l, m))
Next m
R(i) = R(i) - (coef * R(l))
Next l
Next k
Next i
If ((p - Count) < n) Then
output.Value = " infinite solution"
Else
For c = n To 1
sol(c) = R(c)
For b = n To (c - 1)
sol(c) = sol(c) - (a(b, b) * sol(b))
Next b
Next c
End If
For ab = 1 To n
output.Cells(ab, 0) = sol(i)
Next ab
End Sub
thanks
Sourav
I am trying to write a program wich accepts to two arrays one of
coefficients and other of constants and solve it through Gauss
eliminatiion method, the function directly writes the solution in a
colum starting from the given cell
I am not able to trace the problem with the code. though I am new to
excel programming
Can someone help me
The code is as follows:-
Option Base 1
Sub solution(coefficient As Range, constants As Range, output As Range)
p = coefficient.Rows.Count
n = coefficient.coloums.Count
MsgBox ("HI")
Dim a(), R(), sol()
For v = 1 To p
For j = 1 To n
a(v, j) = coefficient(v, j).Value
Next j
R(v) = constants(v).Value
Next v
For i = 1 To n
check = 0
For j = 1 To n
If Not (a(i, j) = 0) Then check = 1
Next j
If check = 0 Then Count = Count + 1
If Not (R(i) = 0) Then
For d = 1 To n
e = a(i, d)
a(i, d) = a((p - Count), d)
a((p - Count), d) = e
Next d
End If
For k = 1 To i
For l = 1 To (i - 1)
coef = a(i, l)
For m = 1 To n
a(i, m) = a(i, m) - (coef * a(l, m))
Next m
R(i) = R(i) - (coef * R(l))
Next l
Next k
Next i
If ((p - Count) < n) Then
output.Value = " infinite solution"
Else
For c = n To 1
sol(c) = R(c)
For b = n To (c - 1)
sol(c) = sol(c) - (a(b, b) * sol(b))
Next b
Next c
End If
For ab = 1 To n
output.Cells(ab, 0) = sol(i)
Next ab
End Sub
thanks
Sourav