Trouble in having access to the cvx variable inside the cvx loop.

조회 수: 7 (최근 30일)
Alireza
Alireza 2023년 9월 20일
댓글: Alireza 2023년 10월 20일
I write this code:
lambda_opt = randn(num_combinations, 1);
cvx_quiet(true);
cvx_begin variable lambda_opt(num_combinations)
minimize(objective_function(lambda_opt, G, rho, optimal_design))
subject to sum(lambda_opt) == 1
lambda_opt >= 0
cvx_end
function obj_param = objective_function(lambda, G, rho, optimal_design)
result_matrix = zeros(size(G,1));
for ind = 1 : length(lambda)
result_matrix = result_matrix + lambda(ind)*G(:,:,ind);
end
% Convert the CVX matrix to a regular MATLAB matrix.
result_matrix = double(result_matrix);
[~,eig_val] = eig(result_matrix);
obj_param = trace_inv(sqrtm(result_matrix)) * max(eig_val);
I did not have access to the matrix "result_matrix" to calculate its eigenvalues. So, I searched about this and find 3 different answers for tackling this and changing this matrix from cvx object to the regular matrix:
  1. result_matrix = value(result_matrix);
  2. result_matrix = cvx_optval.result_matrix;
  3. result_matrix = double(result_matrix);
However, all of these did not work.
I appreciate it if you have any suggestions for this.
  댓글 수: 2
Harsha Vardhan
Harsha Vardhan 2023년 10월 3일
편집: Harsha Vardhan 2023년 10월 3일
Hi, please explain what do you mean by 'I did not have access to the matrix "result_matrix" to calculate its eigenvalues.' What is the error you observed if you use 'results_matrix' directly to calculate the eigen values as follows, after the for loop?
[~,eig_val] = eig(result_matrix);
Alireza
Alireza 2023년 10월 20일
the matrix "result_matrix" created by using the optimal variable. So, you cannot calculate the inverse of that or applying other operator like this.
However, thank you for your answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

arushi
arushi 2023년 10월 17일
Hi Alireza,
 I understand that you are not able to access the “result_matrix” for calculating the eigenvalues. I see that you are trying to convert the cvx object to MATLAB matrix and then trying to calculate the eigen values.
You can try calculating the eigen values directly from the cvx object as all the three functions value ,cvx_optval.result_matrix and double does not provide direct access to 'result_matrix'.
Code:
% Remove the line: result_matrix = double(result_matrix);
% Calculate the eigenvalues of result_matrix
[~, eig_val] = eig(result_matrix);
eigenvalues = diag(eig_val);
Please let me know if this works or the error that you are facing in directly using the cvx object to calculate the eigen values.
  댓글 수: 2
Alireza
Alireza 2023년 10월 20일
You are absolutely correct. However, the specific challenge I'm facing is related to finding the eigenvalues of the inverse of the matrix, not the matrix itself.
Alireza
Alireza 2023년 10월 20일
I have already resolved this issue. I can share the solution with you if you are interested.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Computations에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by