Write a program to calculate the eigenvalues and eigenvectors of a given matrix.
MediumProblem Statement
Write a program to calculate the eigenvalues and eigenvectors of a given matrix.
Sample Input
Matrix: [,1] [,2] [1,] 4 2 [2,] 1 3
Sample Output
[1] "Eigenvalues:"
[1] 5 2
[1] "Eigenvectors:"
[,1] [,2]
[1,] 0.7071068 -0.4472136
[2,] 0.7071068 0.8944272
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
# Predefined structure
matrix <- # Create the matrix
eigen_result <- # Calculate eigenvalues and eigenvectors
print(eigen_result)
Input
Matrix: [,1] [,2] [1,] 4 2 [2,] 1 3
Expected Output
[1] "Eigenvalues:"
[1] 5 2
[1] "Eigenvectors:"
[,1] [,2]
[1,] 0.7071068 -0.4472136
[2,] 0.7071068 0.8944272