Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

Codigo #1

Programacion

Function SumarMatrices(rango1 As String, rango2 As String, rango3 As String)

Dim f1 As Integer, c1 As Integer

Dim f2 As Integer, c2 As Integer

Dim f3 As Integer, c3 As Integer

Dim fs As Integer, cs As Integer

Dim i As Integer, j As Integer

f1 = Range(rango1).Row

c1 = Range(rango1).Column

f2 = Range(rango2).Row

c2 = Range(rango2).Column

f3 = Range(rango3).Row

c3 = Range(rango3).Column

fs = Range(rango1).Rows.Count

cs = Range(rango1).Columns.Count

For i = 0 To fs - 1

For j = 0 To cs - 1

Cells(i + f3, j + c3) = Cells(i + f1, j + c1) + Cells(i + f2, j + c2)

Next

Next

End Function

Private Sub B_1_Click()

SumarMatrices M_1.Text, M_2.Text, M_3.Text

End Sub
Function RestarMatrices(rango1 As String, rango2 As String, rango3 As String)

Dim f1 As Integer, c1 As Integer

Dim f2 As Integer, c2 As Integer

Dim f3 As Integer, c3 As Integer

Dim fs As Integer, cs As Integer

Dim i As Integer, j As Integer

f1 = Range(rango1).Row

c1 = Range(rango1).Column

f2 = Range(rango2).Row

c2 = Range(rango2).Column

f3 = Range(rango3).Row

c3 = Range(rango3).Column

fs = Range(rango1).Rows.Count

cs = Range(rango1).Columns.Count

For i = 0 To fs - 1

For j = 0 To cs - 1

Cells(i + f3, j + c3) = Cells(i + f1, j + c1) - Cells(i + f2, j + c2)

Next

Next

End Function

Private Sub B_2_Click()

RestarMatrices M_1.Text, M_2.Text, M_3.Text

End Sub

Imagen del userform:


Código #2

Function matriz(Ruta As Object) As Variant

Dim a() As Variant

Dim i As Integer, j As Integer

f = Range(Ruta.Text).Row

c = Range(Ruta.Text).Column

fs = Range(Ruta.Text).Rows.Count

cs = Range(Ruta.Text).Columns.Count

ReDim a(1 To fs, 1 To cs)

For i = 1 To fs

For j = 1 To cs

a(i, j) = Cells(f + i - 1, c + j - 1)

Next j

Next i

matriz = a

End Function

Function sumarM(matriz1 As Variant, matriz2 As Variant) As Variant

Dim i As Integer, j As Integer

Dim fs As Integer, cs As Integer

fs = UBound(matriz1, 1)

cs = UBound(matriz1, 2)
Dim result() As Variant

ReDim result(1 To fs, 1 To cs)

For i = 1 To fs

For j = 1 To cs

result(i, j) = matriz1(i, j) + matriz2(i, j)

Next j

Next i

sumarM = result

End Function

Function restarM(matriz1 As Variant, matriz2 As Variant) As Variant

Dim i As Integer, j As Integer

Dim fs As Integer, cs As Integer

fs = UBound(matriz1, 1)

cs = UBound(matriz1, 2)

Dim result() As Variant

ReDim result(1 To fs, 1 To cs)

For i = 1 To fs

For j = 1 To cs

result(i, j) = matriz1(i, j) - matriz2(i, j)

Next j

Next i

restarM = result

End Function

Function productoM(matriz1 As Variant, matriz2 As Variant) As Variant

Dim i As Integer, j As Integer, k As Integer

Dim fsA As Integer, csA As Integer, fsB As Integer, csB As Integer

Dim s As Variant
fsA = UBound(matriz1, 1)

csA = UBound(matriz1, 2)

fsB = UBound(matriz2, 1)

csB = UBound(matriz2, 2)

Dim salida() As Variant

ReDim salida(1 To fsA, 1 To csB)

For i = 1 To fsA

For j = 1 To csB

s=0

For k = 1 To csA

s = s + matriz1(i, k) * matriz2(k, j)

Next k

salida(i, j) = s

Next j

Next i

productoM = salida

End Function

Sub EnviarMatriz(matriz As Variant, s As Object)

Dim i As Integer, j As Integer

Dim fs As Integer, cs As Integer

fs = UBound(matriz, 1)

cs = UBound(matriz, 2)

f = Range(s.Text).Row

c = Range(s.Text).Column

For i = 1 To fs

For j = 1 To cs

Cells(f + i - 1, c + j - 1).Value = matriz(i, j)


Next j

Next i

End Sub

Sub Borrar(s As Object)

f = Range(s.Text).Row

c = Range(s.Text).Column

fs = Range(s.Text).Rows.Count

cs = Range(s.Text).Columns.Count

For i = 1 To fs

For j = 1 To cs

Cells(i + f - 1, j + c - 1) = ""

Next j

Next i

End Sub

Sub Aleatorio(s As Object)

f = Range(s.Text).Row

c = Range(s.Text).Column

fs = Range(s.Text).Rows.Count

cs = Range(s.Text).Columns.Count

For i = 1 To fs

For j = 1 To cs

Cells(i + f - 1, j + c - 1) = Rnd

Next j

Next i

End Sub
Private Sub B_1_Click()

EnviarMatriz sumarM(matriz(M_1), matriz(M_2)), M_3

End Sub

Private Sub B_2_Click()

EnviarMatriz restarM(matriz(M_1), matriz(M_2)), M_3

End Sub

Private Sub B_3_Click()

Borrar M_3

End Sub

Private Sub B_5_Click()

Aleatorio M_3

End Sub

Userform
Codigo #3

Dim foco As Integer

Sub M_1_Enter()

foco = 1

End Sub

Sub M_2_Enter()

foco = 2

End Sub

Sub borra(s As Object)

Dim f As Integer, c As Integer, fs As Integer, cs As Integer

Dim i As Integer, j As Integer

f = Range(s.Text).Row

c = Range(s.Text).Column

fs = Range(s.Text).Rows.Count

cs = Range(s.Text).Columns.Count

For i = 1 To fs

For j = 1 To cs

Cells(i + f - 1, j + c - 1) = ""

Next j

Next i

End Sub
Sub aleatorio(s As Object)

Dim f As Integer, c As Integer, fs As Integer, cs As Integer

Dim i As Integer, j As Integer

f = Range(s.Text).Row

c = Range(s.Text).Column

fs = Range(s.Text).Rows.Count

cs = Range(s.Text).Columns.Count

For i = 1 To fs

For j = 1 To cs

Cells(i + f - 1, j + c - 1) = Rnd

Next j

Next i

End Sub

Private Sub B_1_Click()

If foco = 1 Then aleatorio M_1

If foco = 2 Then aleatorio M_2

End Sub

Private Sub B_2_Click()

If foco = 1 Then borra (M_1)

If foco = 2 Then borra (M_2)

End Sub

CODIGO #4

Dim foco As Integer

Sub M_1_Enter()

foco = 1
End Sub

Sub M_2_Enter()

foco = 2

End Sub

Sub M_3_Enter()

foco = 3

End Sub

Sub borra(s As Object)

Dim f As Integer, c As Integer, fs As Integer, cs As Integer

Dim i As Integer, j As Integer

f = Range(s.Text).Row

c = Range(s.Text).Column

fs = Range(s.Text).Rows.Count

cs = Range(s.Text).Columns.Count

For i = 1 To fs

For j = 1 To cs

Cells(i + f - 1, j + c - 1) = ""

Next j

Next i

End Sub

Sub aleatorio(s As Object)

Dim f As Integer, c As Integer, fs As Integer, cs As Integer

Dim i As Integer, j As Integer


f = Range(s.Text).Row

c = Range(s.Text).Column

fs = Range(s.Text).Rows.Count

cs = Range(s.Text).Columns.Count

For i = 1 To fs

For j = 1 To cs

Cells(i + f - 1, j + c - 1) = Rnd

Next j

Next i

End Sub

Private Sub B_1_Click()

If foco = 1 Then aleatorio M_1

If foco = 2 Then aleatorio M_2

If foco = 3 Then borra M_3

End Sub

Private Sub B_2_Click()

If foco = 1 Then borra M_1

If foco = 2 Then borra M_2

If foco = 3 Then borra M_3

End Sub

Código #5

Function matriz(A As Object) As Variant

Dim f As Integer

Dim c As Integer
Dim fs As Integer

Dim cs As Integer

Dim SALIDA() As Variant

Dim i As Integer

Dim j As Integer

f = Range(A.Text).Row

c = Range(A.Text).Column

fs = Range(A.Text).Rows.Count

cs = Range(A.Text).Columns.Count

ReDim SALIDA(1 To fs, 1 To cs)

For i = 1 To fs

For j = 1 To cs

SALIDA(i, j) = Cells(i + f - 1, j + c - 1).Text

Next j

Next i

matriz = SALIDA

End Function

Sub enviarMatriz(matriz As Variant, A As Object)

Dim fs As Integer

Dim cs As Integer

fs = UBound(matriz, 1)

cs = UBound(matriz, 2)

Dim i As Integer

Dim j As Integer
Dim f As Integer

Dim c As Integer

f = Range(A.Text).Row

c = Range(A.Text).Column

For i = 1 To fs

For j = 1 To cs

Cells(i + f - 1, j + c - 1).Value = matriz(i, j)

Next j

Next i

End Sub

Function ELGauss(A As Variant) As Variant

Dim i As Integer

Dim j As Integer

Dim k As Integer

Dim div As Variant

Dim mul As Variant

Dim m As Integer

Dim n As Integer

m = UBound(A, 1)

n = UBound(A, 2)

Dim B() As Variant

ReDim B(1 To m, 1 To n + 1)
For i = 1 To m

For j = 1 To n

B(i, j) = A(i, j)

Next j

Next i

ReDim resultados(1 To m, 1 To 1)

For i = 1 To m

div = B(i, i)

If div = 0 Then

Dim foundrow As Boolean

foundrow = False

For j = i + 1 To m

If B(j, i) <> 0 Then

Dim temp() As Variant

ReDim tem(1 To n + 1)

For k = 1 To n + 1

temp(k) = B(i, k)

B(i, k) = B(j, k)

B(j, k) = temp(k)

Next k

foundrow = True

Exit For

End If

Next j

div = B(i, i)
End If

For k = 1 To n

B(i, k) = B(i, k) / div

Next k

For j = 1 To m

If j <> i Then

mul = B(j, i)

For k = 1 To n

B(j, k) = B(j, k) - mul * B(i, k)

Next k

End If

Next j

Next i

For i = 1 To m

resultados(i, 1) = A(1, n)

Next i

Dim matrizresultante() As Variant

ReDim matrizresultante(1 To m, 1 To n + 1)

For i = 1 To m

For j = 1 To n

matrizresultante(i, j) = B(i, j)

Next j

matrizresultante(i, n + 1) = resultados(i, 1)

Next i
ELGauss = matrizresultante

End Function

Codigo #6

Function matriz(A As Object) As Variant

Dim f As Integer

Dim c As Integer

Dim fs As Integer

Dim cs As Integer

Dim SALIDA() As Variant

Dim i As Integer

Dim j As Integer

f = Range(A.Text).Row

c = Range(A.Text).Column

fs = Range(A.Text).Rows.Count

cs = Range(A.Text).Columns.Count

ReDim SALIDA(1 To fs, 1 To cs)

For i = 1 To fs

For j = 1 To cs

SALIDA(i, j) = Cells(i + f - 1, j + c - 1).Text

Next j

Next i

matriz = SALIDA
End Function

Sub enviarMatriz(matriz As Variant, A As Object)

Dim fs As Integer

Dim cs As Integer

fs = UBound(matriz, 1)

cs = UBound(matriz, 2)

Dim i As Integer

Dim j As Integer

Dim f As Integer

Dim c As Integer

f = Range(A.Text).Row

c = Range(A.Text).Column

For i = 1 To fs

For j = 1 To cs

Cells(i + f - 1, j + c - 1).Value = matriz(i, j)

Next j

Next i

End Sub

Function ELGauss(A As Variant) As Variant

Dim fs As Integer

Dim cs As Integer

Dim i As Integer

Dim j As Integer
Dim k As Integer

Dim div As Variant

Dim mul As Variant

Dim m As Integer

Dim n As Integer

m = UBound(A, 1)

n = UBound(A, 2)

Dim B() As Variant

ReDim B(1 To m, 1 To n)

B=A

For i = 1 To m

If B(i, i) = 0 Then

'Buscar un elemento no nulo en la misma colunma

For j = i + 1 To n

If B(j, i) <> 0 Then

'Intercambiar filas

For k = 1 To n

Dim temp As Variant

temp = B(i, k)

B(i, k) = B(j, k)

B(j, k) = temp

Next k

Exit For

End If

Next j

End If

div = B(i, i)

If div <> 0 Then

For k = 1 To n
B(i, k) = B(i, k) / div

Next k

End If

For j = 1 To m

If j <> i Then

If B(i, i) <> 0 Then

mul = B(j, i)

For k = 1 To n

B(j, k) = B(j, k) - mul * B(i, k)

Next k

End If

End If

Next j

Next i

ELGauss = B

End Function

Private Sub B_2_Click()

enviarMatriz ELGauss(matriz(M_1)), M_2

End Sub

You might also like