Assume that we are going to solve generalized eigenvalue problem
$$Av = \lambda B v$$
Where $A$ and $B$ are symmetrical matrices.
Assume that we can only use the MATLAB routine [V, D] = eig(X) and not [V, D] = eig(X, Y).
I have heard that by using Cholesky factorization, then I could use [V, D] = eig(X) instead of [V, D] = eig(X, Y).
I have been coding some MATLAB code, but it seems that x != y when I compare the x = Av to y = lambda * B * v
So what should I do so I can solve the generalized eigenvalue problem with cholesky factorization if A and B are symmetrical?
% Generate symmetric and positive definite matrices A and B
A = randn(5, 5);
B = randn(5, 5);
A = A'*A;
B = B'*B;
% Compute the Cholesky factorization of B
L = chol(B, 'lower');
% Solve the linear system L*Y = A for Y using linsolve()
Y = linsolve(L, A);
% Solve the linear system L'*V = Y for V using linsolve()
V = linsolve(L', Y);
% Compute the eigenvalues and eigenvectors of the transformed problem AV = lambdaBV
[eigenvectors, eigenvalues] = eig(V' * A * V);
% Transform the eigenvectors back to the original problem
eigenvectors = V * eigenvectors;
% Check that A*v = lambda*B*v for each eigenvector v and corresponding eigenvalue lambda
for i = 1:length(eigenvalues)
lambda = eigenvalues(i);
v = eigenvectors(:,i);
x = A * v
y = lambda * B * v
assert(norm(x - y) < 1e-10);
end