[Gambas-user] Long C routine
Ing Martín Cristiá
tercoide at ...67...
Sun Feb 2 13:25:26 CET 2014
Emil, this is the basic code. For the test, the Wait 0.01 were erased.Also the functions Addbanda(), DeBanda(), are just to locate the (row,col) element of the matrix in the array that contains it. That array cant be embedded as suggested because its size us unknown.
Public Function solucionarXgauss(x As Float[], ti As Float[], iOrden As Integer) As Integer
' OK GAMBAS ?
Dim c1 As Float
Dim i As Integer, j As Integer, a As Integer, b As Integer, ok As Integer
Dim l As Integer, h As Integer, i1 As Integer, j1 As Integer
Dim p1 As Float
contador = 0
If iOrden = 0 Then Return 0
ok = True
'usa el metodo de Gauss
'debe ser cuadrada la matriz
' triangulacion
For i = 0 To iOrden - 1
Wait 0.001 'necesario para el ambiente
If debanda(i, i) <> 0 Then
For j = i + 1 To iOrden - 1
If debanda(j, i) <> 0 Then
c1 = - debanda(j, i) / debanda(i, i)
For h = i To iOrden - 1
addbanda(j, h, c1 * debanda(i, h))
Next
ti[j] = ti[j] + c1 * ti[i]
End If
Next
Else
Return
l = i
If i = iOrden - 1 Or l > iOrden - 1 Then Return 0 ' el sistema es incompatible
Do
If debanda(l, i) <> 0 Then
For h = 0 To iOrden - 1
addbanda(i, h, debanda(l, h))
Next
ti[i] = ti[i] + ti[l]
Exit
Else
l = l + 1
If i = iOrden - 1 Or l > iOrden - 1 Then Return 0 ' el sistema es incompatible
End If
Loop
End If
Next
' sustitucion atrás
x[iOrden - 1] = ti[iOrden - 1] / debanda(iOrden - 1, iOrden - 1)
For i = iOrden - 2 To 0 Step -1
Wait 0.001 'necesario para el ambiente
p1 = 0
For j = i + 1 To iOrden - 1
p1 = p1 - x[j] * debanda(i, j)
Next
p1 = ti[i] + p1
x[i] = p1 / debanda(i, i)
Next
Return ok
End Function
Ing Martin Cristia
More information about the User
mailing list