SoloCodigo

Programación General => Visual Basic 6.0 e inferiores => Mensaje iniciado por: Dhanny en Miércoles 26 de Septiembre de 2007, 19:05

Título: Multiplicar Matrices
Publicado por: Dhanny en Miércoles 26 de Septiembre de 2007, 19:05
Hola amigos, necesito automatizar la multiplicacion de dos matrices, la primera debo ingresar los datos la seguunda igual y en la tercera me de el resultado de la multiplicacion de ambas.

Pueden ayudarme por favor,

Gracias
Título: Re: Multiplicar Matrices
Publicado por: Jose Arriagada en Viernes 30 de Noviembre de 2007, 17:09
Coloca los siguientes controles en el formulario, en las posiciones que te indico

label1     text1      text2

label2     text3      text4


command1          command2

Y ahora copia, este codigo completo en el formulario... y prueba...

Dim Matriz1(1 To 10, 1 To 10) As Double

Dim Matriz2(1 To 10, 1 To 10) As Double
Dim Matriz3(1 To 10, 1 To 10) As Double


Private Sub Command1_Click()
    For i = 1 To Text1.Text
        For j = 1 To Text2.Text
            Matriz1(i, j) = InputBox("Ingresar valor (" & i & ":" & j & ")", "Ingreso Matriz 1")
        Next j
    Next i
    For i = 1 To Text3.Text
        For j = 1 To Text4.Text
            Matriz2(i, j) = InputBox("Ingresar valor (" & i & ":" & j & ")", "Ingreso Matriz 2")
        Next j
    Next i
    Command2.Enabled = True
End Sub

Private Sub Command2_Click()
msg = Empty
For i = 1 To Text1.Text
    For j = 1 To Text4.Text
        For k = 1 To Text3.Text
            Matriz3(i, j) = Matriz3(i, j) + Matriz1(i, k) * Matriz2(k, j)
        Next k
        msg = msg & "(" & i & ":" & j & ")=" & Matriz3(i, j) & "     "
    Next j
    msg = msg & vbLf
Next i
msg = msg & vbLf
MsgBox msg
End Sub

Private Sub Form_Load()
    Label1.Caption = "Matriz 1"
    Text1.Text = ""
    Text2.Text = ""
    Label2.Caption = "Matriz 2"
    Text3.Text = ""
    Text4.Text = ""
    Command1.Caption = "Ingresar valores..."
    Command2.Caption = "Calcular..."
    Command2.Enabled = False
       
End Sub



Las correcciones, verificaciones y validaciones te las dejo, para que le pongas un poco de tus sesos...