This task is similar to:

   Matrix multiplication
   Matrix transposition


Task

Implement basic element-wise matrix-matrix and scalar-matrix operations, which can be referred to in other, higher-order tasks.

Implement:

   addition
   subtraction
   multiplication
   division
   exponentiation


Extend the task if necessary to include additional basic operations, which should not require their own specialised task.




Dim Shared As Double a(1,2) = {{7, 8, 7}, {4, 0, 9}}
Dim Shared As Double b(1,2) = {{4, 5, 1}, {6, 2, 1}}
Dim Shared As Double c(1,2)
Dim Shared As Double fila, columna
Dim Shared As String p
 
Sub list(a() As Double)
    p = "["
    For fila = 0 To Ubound(a,1)
        p &= "["
        For columna = 0 To Ubound(b,2)
            p &= Str(a(fila, columna)) + ", "
        Next columna
        p = Left(p,Len(p)-2) + "]"
    Next fila
    p &= "]"
    Print p;
End Sub
 
REM Matrix-Matrix:
Sub Mostrarmm(a() As Double, op As String, b() As Double, c() As Double)
    list(a()) : Print " "; op; " "; : list(b()) : Print " = "; : list(c()) : Print
End Sub
 
Sub addmm(a() As Double, b() As Double, c() As Double)
    REM adición
    For fila = Lbound(a,1) To Ubound(a,1)
        For columna = Lbound(b,2) To Ubound(b,2)
            c(fila, columna) = a(fila,columna) + b(fila,columna)
        Next columna
    Next fila
End Sub
 
Sub resmm(a() As Double, b() As Double, c() As Double)
    REM sustracción
    For fila = Lbound(a,1) To Ubound(a,1)
        For columna = Lbound(b,2) To Ubound(b,2)
            c(fila, columna) = a(fila,columna) - b(fila,columna)
        Next columna
    Next fila
End Sub
 
Sub mulmm(a() As Double, b() As Double, c() As Double)
    REM multiplicación
    For fila = Lbound(a,1) To Ubound(a,1)
        For columna = Lbound(b,2) To Ubound(b,2)
            c(fila, columna) = a(fila,columna) * b(fila,columna)
        Next columna
    Next fila
End Sub
 
Sub divmm(a() As Double, b() As Double, c() As Double)
    REM división
    For fila = Lbound(a,1) To Ubound(a,1)
        For columna = Lbound(b,2) To Ubound(b,2)
            c(fila, columna) = a(fila,columna) / b(fila,columna)
        Next columna
    Next fila
End Sub
 
Sub powmm(a() As Double, b() As Double, c() As Double)
    REM exponenciación
    For fila = Lbound(a,1) To Ubound(a,1)
        For columna = Lbound(b,2) To Ubound(b,2)
            c(fila, columna) = a(fila,columna) ^ b(fila,columna)
        Next columna
    Next fila
End Sub
 
REM Matrix-Scalar:
Sub Mostrarms(a() As Double, op As String, b As Double, c() As Double)
    list(a()) : Print " "; op; " "; Str(b); " = "; : list(c()) : Print
End Sub
 
Sub addms(a() As Double, b As Double, c() As Double)
    REM adición
    For fila = Lbound(a,1) To Ubound(a,1)
        For columna = Lbound(a,2) To Ubound(a,2)
            c(fila, columna) = a(fila,columna) + b
        Next columna
    Next fila
End Sub
 
Sub resms(a() As Double, b As Double, c() As Double)
    REM sustracción
    For fila = Lbound(a,1) To Ubound(a,1)
        For columna = Lbound(a,2) To Ubound(a,2)
            c(fila, columna) = a(fila,columna) - b
        Next columna
    Next fila
End Sub
 
Sub mulms(a() As Double, b As Double, c() As Double)
    REM multiplicación
    For fila = Lbound(a,1) To Ubound(a,1)
        For columna = Lbound(a,2) To Ubound(a,2)
            c(fila, columna) = a(fila,columna) * b
        Next columna
    Next fila
End Sub
 
Sub divms(a() As Double, b As Double, c() As Double)
    REM división
    For fila = Lbound(a,1) To Ubound(a,1)
        For columna = Lbound(a,2) To Ubound(a,2)
            c(fila, columna) = a(fila,columna) / b
        Next columna
    Next fila
End Sub
 
Sub powms(a() As Double, b As Double, c() As Double)
    REM exponenciación
    For fila = Lbound(a,1) To Ubound(a,1)
        For columna = Lbound(a,2) To Ubound(a,2)
            c(fila, columna) = a(fila,columna) ^ b
        Next columna
    Next fila
End Sub
 
REM Matrix-Matrix:
addmm(a(), b(), c()) : Mostrarmm(a(), "+", b(), c())
resmm(a(), b(), c()) : Mostrarmm(a(), "-", b(), c())
mulmm(a(), b(), c()) : Mostrarmm(a(), "*", b(), c())
divmm(a(), b(), c()) : Mostrarmm(a(), "/", b(), c())
powmm(a(), b(), c()) : Mostrarmm(a(), "^", b(), c())
Print
REM Matrix-Scalar:
addms(a(), 3, c()) : Mostrarms(a(), "+", 3, c())
resms(a(), 3, c()) : Mostrarms(a(), "-", 3, c())
mulms(a(), 3, c()) : Mostrarms(a(), "*", 3, c())
divms(a(), 3, c()) : Mostrarms(a(), "/", 3, c())
powms(a(), 3, c()) : Mostrarms(a(), "^", 3, c())
Sleep