Eigenvalue problem optimized with lqsnonlin
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fabio Cavagna
el 3 de Ag. de 2023
Comentada: Matt J
el 22 de Oct. de 2024 a las 12:13
Hello everyone,
I have the generalized eigenvalue problem (K-w^2*M)*R = 0 where
K is a 6x6 diagonal matrix whose values are unknown,
M is a 6x6 matrix whose values are known,
w^2 are the eigenvalues (typically called lambda) and they are known through f ( w = 2*pi*f )
R are the eigenvectors
I would like to obtain the diagonal values of K that minimize the difference between f_exact (my values) and f_calc evaluated through iterations.
I tried with lsqnonlin but the f_calc is far from my f_exact.
Does anyone know how to optimize in a better way?
Here's my code:
% M matrix
M = diag([1e3, 1e3, 1e3, 1e5, 1e5, 1e5]);
M(1,4) = 100; M(4,1) = 100; M(1,5) = 150; M(5,1) = 150;
M(2,6) = 10; M(6,2) = 10; M(3,6) = 1; M(6,3) = 1;
M(2,3) = 30; M(3,2) = 30; M(3,5) = 500; M(5,3) = 500;
f_exact = [30, 30, 100, 10, 10, 20]; %lambda = (2*pi*f)^2
K_guess = [1e8, 1e8, 1e8, 1e8, 1e8, 1e8]; %Initial guess
LB = [1, 1, 1, 1, 1, 1];
UB = [1e15, 1e15, 1e15, 1e15, 1e15, 1e15];
options = optimoptions('lsqnonlin','FunctionTolerance',1e-16);
K_opt = lsqnonlin(@(K) obj_function(K, M, f_exact),K_guess,LB,UB,options);
%% Check
K_check = diag(K_opt);
[R,L] = eig(K_check,M);
f_calc = diag(sqrt(L)./(2*pi));
function diff = obj_function(K, M, f_exact)
K_mat = diag(K);
[R,L] = eig(K_mat,M);
eig_calc = diag(L);
f_calc = sqrt(eig_calc)./(2*pi)
diff = f_calc - f_exact;
end
2 comentarios
Torsten
el 3 de Ag. de 2023
At least you should sort given and calculated eigenvalues before comparing them.
Sam Chak
el 4 de Ag. de 2023
It's good to learn optimization with lqsnonlin. However, in this eigenvalue problem, the algorithm is kind of defeating the purpose because your objective function depends eig() computation itself.
Might as well use eig() directly to find the eigenvalues. You can use eig() for checking the accuracy, but not relying on it to solve the problem.
The logical question is how can the objective function be formulated without eig()?
Respuesta aceptada
Matt J
el 3 de Ag. de 2023
Editada: Matt J
el 3 de Ag. de 2023
% M matrix
M = diag([1e3, 1e3, 1e3, 1e5, 1e5, 1e5]);
M(1,4) = 100; M(4,1) = 100; M(1,5) = 150; M(5,1) = 150;
M(2,6) = 10; M(6,2) = 10; M(3,6) = 1; M(6,3) = 1;
M(2,3) = 30; M(3,2) = 30; M(3,5) = 500; M(5,3) = 500;
f_exact = [30, 30, 100, 10, 10, 20];
K_guess = ((2*pi*f_exact(:)).^2.*diag(M))'; %<---- better initial guess
LB = [1, 1, 1, 1, 1, 1];
UB = [1e15, 1e15, 1e15, 1e15, 1e15, 1e15];
options = optimoptions('lsqnonlin','FunctionTolerance',1e-16,'StepTol',1e-16, 'OptimalityTol',1e-12,'MaxFunEvals',inf);
[K_opt,~,res] = lsqnonlin(@(K) obj_function(K, M, f_exact),K_guess,LB,UB,options);
%% Check
K_check = diag(K_opt);
[R,L] = eig(K_check,M);
f_calc = diag(sqrt(L)./(2*pi)).';
sort(f_calc) %<---compare sorted
sort(f_exact)
function diff = obj_function(K, M, f_exact)
K_mat = diag(K);
[R,L] = eig(K_mat,M);
eig_calc = diag(L).'; %<---transpose
f_calc = sqrt(eig_calc)./(2*pi);
diff = sort(f_calc) - sort(f_exact); %<---compare sorted
end
7 comentarios
Matt J
el 22 de Oct. de 2024 a las 12:13
I'm afraid not. I have no reason to believe it should work.
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!