Learn R Programming

matlib (version 0.8.1)

power_method: Power Method for Eigenvectors

Description

Finds a dominant eigenvalue and its corresponding eigenvector of a square matrix by applying the Power Method with scaling

Usage

power_method(X, v = NULL, eps = 1e-06, maxiter = 100, verbose = FALSE)

Arguments

X

a square numeric matrix

v

optional starting vector

eps

convergence threshold

maxiter

maximum number of iterations

verbose

logical; if TRUE, show the approximation to the eigenvector at each iteration

Value

a list containing the eigenvector, eigenvalue, and iterations

Examples

Run this code
# NOT RUN {
A = cbind(c(2, 1), c(12, 5))
power_method(A)
eigen(A)$vectors[,1]  # check

B = cbind(c(1, 2, 0), c(2, 1, 3), c(0, 3, 1))
power_method(B)
# }

Run the code above in your browser using DataLab