Sie sind auf Seite 1von 6

Public Class Form1 Private Sub Generar_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Generar.

Click Dim n As Single n = Val(txtN.Text) 'Cantidad de filas y columnas para el grid' Tabla1.RowCount = n Tabla1.ColumnCount = n Tabla2.RowCount = n Tabla2.ColumnCount = 1 Tabla3.RowCount = n Tabla3.ColumnCount = 1 'la cantidad de filas y columnas para cada matriz, en este caso las matr ices ordenadas' Tabla4.RowCount = n Tabla4.ColumnCount = n Tabla5.RowCount = n Tabla5.ColumnCount = 1 Tabla6.RowCount = n Tabla6.ColumnCount = 1

'***********ocultar los headers de todos los grid, para que tengan forma de una matriz************ Tabla1.RowHeadersVisible = False Tabla1.ColumnHeadersVisible = False Tabla2.ColumnHeadersVisible = False Tabla2.RowHeadersVisible = False Tabla3.ColumnHeadersVisible = False Tabla3.RowHeadersVisible = False '***********centrear datos en los grid**************' Tabla1.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.Mid dleCenter Tabla2.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.Mid dleCenter Tabla3.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.Mid dleCenter 'Con estos cdigos se ponen invisibles los headers del grid, para que se v ea como una matriz real' Tabla4.RowHeadersVisible = False Tabla5.RowHeadersVisible = False Tabla6.RowHeadersVisible = False Tabla4.ColumnHeadersVisible = False Tabla5.ColumnHeadersVisible = False Tabla6.ColumnHeadersVisible = False '*********Centrear datos en los grid***************' Tabla4.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.Mid dleCenter Tabla5.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.Mid dleCenter

Tabla6.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.Mid dleCenter

End Sub Private Sub Ordenar_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Ordenar.Click Dim R, S As Integer, y As Single, W As Integer, M1(,) As String, L0 As I nteger, k0 As Integer, Li As Integer, B() As String, C() As String, D() As Strin g, L As Single, K As Single Dim C1 As Double, c2 As Double, z As Integer y = Val(txtN.Text) ReDim B(y), C(y) ReDim D(y) ReDim M1(y, y) '********Declaracin de variables*********' Tabla2.RowCount = y Tabla2.ColumnCount = 1 Tabla4.RowCount = y Tabla4.ColumnCount = y Tabla1.RowCount = y Tabla1.ColumnCount = y 'Movimiento de la matriz de las variables' L = 0 K = 0 'Ciclo para determinar el nmero de incognitas y nmeros For R = 0 To y - 1 If IsNumeric(Tabla2.Rows(R).Cells(0).Value) = False Then Li = Li + 1 End If Next 'Ciclo para ordenar el vector de las incognitas For R = 0 To y - 1 If IsNumeric(Tabla2.Rows(R).Cells(0).Value) = False Then B(L) = Tabla2.Rows(R).Cells(0).Value For z = 0 To y - 1 M1(z, L) = Tabla1.Rows(z).Cells(R).Value Next L = L + 1 Else D(K) = Tabla2.Rows(R).Cells(0).Value For z = 0 To y - 1

M1(z, Li + K) = Tabla1.Rows(z).Cells(R).Value Next K = K + 1 End If Next C1 = L For W = 0 To L - 1 C(W) = B(W) Next For W = L To y - 1 C(W) = D(W - L) C1 = C1 + 1 Next For R = 0 To y - 1 Tabla5.Rows(R).Cells(0).Value = C(R) Next For R = 0 To y - 1 For S = 0 To y - 1 Tabla4.Rows(R).Cells(S).Value = M1(R, S) Next Next '*********************Ordenando los terminos libres********************* **** Dim G() As String, M2() As String, M3() As String, U() As String, F() As String, L1 As Single, K1 As Single, P() As String, Q(,) As String ReDim F(y), G(y), P(y), M2(K), M3(y), U(y) L1 = 0 K1 = 0 k0 = 0 L0 = 0 For R = 0 To y - 1 If IsNumeric(Tabla3.Rows(R).Cells(0).Value) = True Then L0 = L0 + 1 Else k0 = k0 + 1 End If Next

For R = 0 To y - 1 If IsNumeric(Tabla3.Rows(R).Cells(0).Value) = True Then G(L1) = Tabla3.Rows(R).Cells(0).Value For z = 0 To y - 1 M1(L1, z) = Tabla4.Rows(R).Cells(z).Value Next L1 = L1 + 1

Else F(K1) = Tabla3.Rows(R).Cells(0).Value For z = 0 To y - 1 M1(L0 + K1, z) = Tabla4.Rows(R).Cells(z).Value Next K1 = K1 + 1 End If Next For W = 0 To L1 - 1 P(W) = G(W) Next For W = L1 To y - 1 P(W) = F(W - L1) Next For R = 0 To y - 1 Tabla6.Rows(R).Cells(0).Value = Tabla3.Rows(R).Cells(0).Value Next For R = 0 To y - 1 For S = 0 To y - 1 Tabla4.Rows(R).Cells(S).Value = M1(R, S) Next Next For R = 0 To y - 1 Tabla5.Rows(R).Cells(0).Value = C(R) Next For R = 0 To y - 1 Tabla6.Rows(R).Cells(0).Value = P(R) Next '********separacion de las matrices***************** 'Multiplicacion de valores conocidos For R = 0 To L - 1 c2 = 0 For W = L To y - 1 C1 = Val(M1(R, W)) * Val(D(W - L)) c2 = c2 + C1 Next U(R) = Val(G(R)) - c2 Next 'Matris de incognitas final ReDim Q(L, L + 1)

For R = 0 To L - 1 For W = 0 To L - 1 Q(R, W) = M1(R, W) Next Next For W = 0 To L Q(W, L) = U(W) Next

'Eliminacin de Gauss Dim A(,), X() As Double Dim N, I, J As Integer Dim Mensaje As String N = L ReDim A(N, N + 1), X(N) For I = 1 To N For J = 1 To N + 1 A(I, J) = Q(I - 1, J - 1) Next Next

ELI_GAUSS(N, A, X, Mensaje) TextBox1.Text = Mensaje If Mensaje <> "El sistema tiene Solucin nica" Then Resultados.Rows.Clear() Resultados.Columns.Clear() Exit Sub End If Resultados.Rows.Clear() Resultados.Columns.Clear() Resultados.ReadOnly = True Resultados.RowCount = N + 1 Resultados.ColumnCount = 2 resultados1.RowCount = K + 1 resultados1.ColumnCount = 2

Resultados.DefaultCellStyle.Alignment = DataGridViewContentAlignment.Mid dleCenter Resultados.Rows(0).Cells(1).Value = "Valor" Resultados.Rows(0).Height = 40 Resultados.Columns(0).Width = 50 For I = 1 To N Resultados.Rows(I).Cells(0).Value = C(I - 1) & " = " Resultados.Rows(I).Cells(1).Value = X(I) Resultados.Rows(I).Cells(1).Style.Format = "0.0000" Next For R = 0 To L - 1 M3(R) = X(R + 1) Next For R = L To y - 1 M3(R) = D(R - L) Next

'Valores de b For R = L To y - 1 c2 = 0 For W = 0 To y - 1 C1 = Val(M1(R, W)) * Val(M3(W)) c2 = c2 + C1 Next M2(R - L) = c2 Next resultados1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.Mi ddleCenter resultados1.Rows(0).Cells(1).Value = "Valor" resultados1.Rows(0).Height = 40 resultados1.Columns(0).Width = 50 For I = 1 To K resultados1.Rows(I).Cells(0).Value = F(I - 1) & " = " resultados1.Rows(I).Cells(1).Value = M2(I - 1) resultados1.Rows(I).Cells(1).Style.Format = "0.0000" Next End Sub End Class

Das könnte Ihnen auch gefallen