[英]how to produce a plot using different powers of matrix
要計算矩陣的力量,你可以使用expm
包或matrixcalc
包:
A <- toeplitz(c(1,2,3)) # a square matrix
A
# [,1] [,2] [,3]
# [1,] 1 2 3
# [2,] 2 1 2
# [3,] 3 2 1
library(expm)
A %^% 2
# [,1] [,2] [,3]
# [1,] 14 10 10
# [2,] 10 9 10
# [3,] 10 10 14
library(matrixcalc)
matrix.power(A, 2)
# [,1] [,2] [,3]
# [1,] 14 10 10
# [2,] 10 9 10
# [3,] 10 10 14
對於情節:
powers <- 0:8
Apowers <- lapply(powers, function(k) A %^% k)
norms <- sapply(Apowers, norm, type = "1")
plot(powers, norms)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.