source('utils.R') n = 6 ## tester size ##n = 20 ## official problem size A = build_tridiagonal_matrix(n, 4, -1, -1) if(n <= 10){ print('A=') print(A) } pm = power_method(A, tol=1e-6) exact = exact_tridiagonal_eigensystem(n, 4, -1) ## Compare our results with the exact results: ## print(sprintf('my eigenvalue= %f; exact eigenvalue= %f; error= %f', pm$max_eigenvalue, exact$lambda[n], exact$lambda[n]-pm$max_eigenvalue) ) print('my eigenvector=') print(pm$max_eigenvector) print('exact eigenvector=') ee = exact$U[, n]; dim(ee) = c(n, 1) ee = ee/norm(ee, '2') ## normalize to the same norm as the outputs from the power_method print(ee) print(sprintf('norm of the difference= %f', norm(pm$max_eigenvector-ee,'2')))