Eigenvalue problem optimized with lqsnonlin
조회 수: 6 (최근 30일)
이전 댓글 표시
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
Torsten
2023년 8월 3일
At least you should sort given and calculated eigenvalues before comparing them.
Sam Chak
2023년 8월 4일
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()?
채택된 답변
Matt J
2023년 8월 3일
편집: Matt J
2023년 8월 3일
% 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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!