Learn R Programming

SPA3G (version 1.0)

TT:

Returns the trace of the product of two matrices

Description

TT function calculates diagal elements of the product of two matrices and sum them up to return as the trace.

Usage

TT(M1, M2)

Arguments

M1
matrix

M2
matrix

Value

Examples

Run this code


## The function is currently defined as
function (M1, M2) 
{
    nn <- nrow(M1)
    S <- c()
    for (itt in 1:nn) {
        S[itt] <- sum(M1[itt, ] * M2[, itt])
    }
    trace <- sum(S)
    return(trace)
  }

Run the code above in your browser using DataLab