Matrix inverse in objective function

7 visualizaciones (últimos 30 días)
Sai Srikar
Sai Srikar el 17 de Nov. de 2023
Editada: Sai Srikar el 17 de Nov. de 2023
Hi,
I am trying to find the matrix X, which minimizes the objective function. However, I see the following error:
Error using inv
Invalid data type. Input matrix must be double or single.
Error in t2 (line 11)
prob.Objective=trace(R - R*X'*inv(X*R*X' + sigma2*eye(T))*X*R);
My code snippet: (Here, T, N and sigma2 are constants and R is an NxN PSD matrix)
prob=optimproblem("Description","MSE min")
X=optimvar("X",T,N,"Type",'continuous');
prob.Objective=trace(R - R*X'*inv(X*R*X' + sigma2*eye(T))*X*R);
  5 comentarios
Walter Roberson
Walter Roberson el 17 de Nov. de 2023
Do not use inv() here. Use the \ operator
Sai Srikar
Sai Srikar el 17 de Nov. de 2023
Hi, I tried \ operator like: prob.Objective = trace(R - R*X'*(X*R*X' + sigma2*eye(T))/(X*R)). I still get an error as follows:
Error using /
Division of an OptimizationVariable by nonscalar not supported.

Iniciar sesión para comentar.

Respuesta aceptada

Bruno Luong
Bruno Luong el 17 de Nov. de 2023
  1 comentario
Sai Srikar
Sai Srikar el 17 de Nov. de 2023
Editada: Sai Srikar el 17 de Nov. de 2023
Thanks Bruno, I am able to get rid of the error.

Iniciar sesión para comentar.

Más respuestas (2)

Himanshu
Himanshu el 17 de Nov. de 2023
Hey,
I understand that you are an encountering an error while running the given code snippet.
The error message indicates that the error occurs because the inv function is being called with inputs of invalid datatype. The inv function only accepts inputs of type double or single. In the given code,inv function is trying to operate on an expression involving an optimization variable (X), which is not of type double or single.
Please refer to the following documentation page for more information on the inv function:
  1 comentario
Sai Srikar
Sai Srikar el 17 de Nov. de 2023
Thanks Himanshu. Is there any way to address this issue in MATLAB?, I do know the analytical solution for this optimization problem, I wanted to reproduce the same using MATALAB's optimization toolbox for my work.

Iniciar sesión para comentar.


Pratyush
Pratyush el 17 de Nov. de 2023
Hi Sai,
I understand that you are getting an error using the "inv" function.
The error you receive is because the "inv" function accepts matrix of data type single or double as argument, but it seems your "X*R*X' + sigma2*eye(T)" expression is not of the correct type.
To fix this issue, you can explicitly convert the matrix to the desired type using the "double" function. Try modifying the last line of your script to :
prob.Objective = trace(R - R*X'*inv(double(X*R*X' + sigma2*eye(T)))*X*R);
  1 comentario
Sai Srikar
Sai Srikar el 17 de Nov. de 2023
Thanks Pratyush, I tried this. I get a new error: "Error using double
Conversion to double from optim.problemdef.OptimizationExpression is not possible."

Iniciar sesión para comentar.

Categorías

Más información sobre Problem-Based Optimization Setup en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by