Win_odd Dhamnekar
Junior Member
- Joined
- Aug 14, 2018
- Messages
- 212
In 'R' while using D.matrix(n) or duplication.matrix (n) function,where n=3, we get following answer.
> D.matrix(3)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 0 0 0 0 0
[2,] 0 1 0 0 0 0
[3,] 0 0 1 0 0 0
[4,] 0 1 0 0 0 0
[5,] 0 0 0 1 0 0
[6,] 0 0 0 0 1 0
[7,] 0 0 1 0 0 0
[8,] 0 0 0 0 1 0
[9,] 0 0 0 0 0 1
>
Where
> u.vectors(3)
$k
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 2 4 0
[3,] 3 5 6
$I
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 0 0 0 0 0
[2,] 0 1 0 0 0 0
[3,] 0 0 1 0 0 0
[4,] 0 0 0 1 0 0
[5,] 0 0 0 0 1 0
[6,] 0 0 0 0 0 1
Source programme(code) for D.matrix is below.
> getAnywhere(D.matrix)
A single object matching ‘D.matrix’ was found
It was found in the following places
package:matrixcalc
namespace:matrixcalc
with value
function (n)
{
if (missing(n))
stop("argument n is missing")
if (!is.numeric(n))
stop("argument n is not numeric")
if (n != trunc(n))
stop("argument n is not an integer")
if (n < 2)
stop("argument n is less than 2")
p <- n * (n + 1)/2
nsq <- n * n
Dt <- matrix(0, nrow = p, ncol = nsq)
T <- T.matrices(n)
u <- u.vectors(n)
k <- u$k
I <- u$I
for (j in 1:n) {
for (i in j:n) {
Dt <- Dt + I[, k[i, j]] %*% t(vec(T[][[j]]))
}
}
return(t(Dt))
}
<bytecode: 0x000002926d7892e0>
<environment: namespace:matrixcalc>
> T.matrices(3)
[[1]]
[[1]][[1]]
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 0 0
[3,] 0 0 0
[[1]][[2]]
[,1] [,2] [,3]
[1,] 0 1 0
[2,] 1 0 0
[3,] 0 0 0
[[1]][[3]]
[,1] [,2] [,3]
[1,] 0 0 1
[2,] 0 0 0
[3,] 1 0 0
[[2]]
[[2]][[1]]
[,1] [,2] [,3]
[1,] 0 1 0
[2,] 1 0 0
[3,] 0 0 0
[[2]][[2]]
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 1 0
[3,] 0 0 0
[[2]][[3]]
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 1
[3,] 0 1 0
[[3]]
[[3]][[1]]
[,1] [,2] [,3]
[1,] 0 0 1
[2,] 0 0 0
[3,] 1 0 0
[[3]][[2]]
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 1
[3,] 0 1 0
[[3]][[3]]
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
[3,] 0 0 1
Now I don't understand how did this 'matrixcalc' package compute t ( vec ( T [ [ i ]] [ [ j ] ] ) ) and multiply itself with Dt + I [ , k[ i , j ] ]?
Would any member of this forum explain?
I shall ask this question to author of this package also.
> D.matrix(3)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 0 0 0 0 0
[2,] 0 1 0 0 0 0
[3,] 0 0 1 0 0 0
[4,] 0 1 0 0 0 0
[5,] 0 0 0 1 0 0
[6,] 0 0 0 0 1 0
[7,] 0 0 1 0 0 0
[8,] 0 0 0 0 1 0
[9,] 0 0 0 0 0 1
>
Where
> u.vectors(3)
$k
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 2 4 0
[3,] 3 5 6
$I
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 0 0 0 0 0
[2,] 0 1 0 0 0 0
[3,] 0 0 1 0 0 0
[4,] 0 0 0 1 0 0
[5,] 0 0 0 0 1 0
[6,] 0 0 0 0 0 1
Source programme(code) for D.matrix is below.
> getAnywhere(D.matrix)
A single object matching ‘D.matrix’ was found
It was found in the following places
package:matrixcalc
namespace:matrixcalc
with value
function (n)
{
if (missing(n))
stop("argument n is missing")
if (!is.numeric(n))
stop("argument n is not numeric")
if (n != trunc(n))
stop("argument n is not an integer")
if (n < 2)
stop("argument n is less than 2")
p <- n * (n + 1)/2
nsq <- n * n
Dt <- matrix(0, nrow = p, ncol = nsq)
T <- T.matrices(n)
u <- u.vectors(n)
k <- u$k
I <- u$I
for (j in 1:n) {
for (i in j:n) {
Dt <- Dt + I[, k[i, j]] %*% t(vec(T[][[j]]))
}
}
return(t(Dt))
}
<bytecode: 0x000002926d7892e0>
<environment: namespace:matrixcalc>
> T.matrices(3)
[[1]]
[[1]][[1]]
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 0 0
[3,] 0 0 0
[[1]][[2]]
[,1] [,2] [,3]
[1,] 0 1 0
[2,] 1 0 0
[3,] 0 0 0
[[1]][[3]]
[,1] [,2] [,3]
[1,] 0 0 1
[2,] 0 0 0
[3,] 1 0 0
[[2]]
[[2]][[1]]
[,1] [,2] [,3]
[1,] 0 1 0
[2,] 1 0 0
[3,] 0 0 0
[[2]][[2]]
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 1 0
[3,] 0 0 0
[[2]][[3]]
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 1
[3,] 0 1 0
[[3]]
[[3]][[1]]
[,1] [,2] [,3]
[1,] 0 0 1
[2,] 0 0 0
[3,] 1 0 0
[[3]][[2]]
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 1
[3,] 0 1 0
[[3]][[3]]
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
[3,] 0 0 1
Now I don't understand how did this 'matrixcalc' package compute t ( vec ( T [ [ i ]] [ [ j ] ] ) ) and multiply itself with Dt + I [ , k[ i , j ] ]?
Would any member of this forum explain?
I shall ask this question to author of this package also.