library(Matrix)
library(ggplot2)
A <- matrix(c(4, 2+3i, 2-3i, 5), nrow = 2, byrow = TRUE)
eigen_result <- eigen(A)
eigenvectors <- eigen_result$vectors
print(eigenvectors)
##                       [,1]                  [,2]
## [1,] -0.6567494+0.0000000i -0.7541089+0.0000000i
## [2,] -0.4183044+0.6274566i  0.3642990-0.5464485i
eigenvectors_df <- data.frame(Re1 = Re(eigenvectors[, 1]), Im1 = Im(eigenvectors[, 1]),
                              Re2 = Re(eigenvectors[, 2]), Im2 = Im(eigenvectors[, 2]))
ggplot(eigenvectors_df, aes(x = Re1, y = Im1, color = "Eigenvector 1")) +
  geom_point(size = 4) +
  geom_segment(aes(x = 0, y = 0, xend = Re1, yend = Im1), arrow = arrow(length = unit(0.2, "cm")), color = "blue") +
  geom_point(aes(x = Re2, y = Im2, color = "Eigenvector 2"), size = 4) +
  geom_segment(aes(x = 0, y = 0, xend = Re2, yend = Im2), arrow = arrow(length = unit(0.2, "cm")), color = "red") +
  labs(x = "Real", y = "Imaginary") +
  theme_minimal() +
  scale_color_manual(values = c("Eigenvector 1" = "blue", "Eigenvector 2" = "red"))