How to multiply a vector of symbolic variables by a 3D matrix, for supplying to cvx?

2 views (last 30 days)
I have a vector y:
y = [y1,y2..y25]
I also have a 3D matrix A, 10x10x25.
I need to create an expression B:
B = y1*A(:,:,1) + y2*(A:,:,2) + ... + y25*A(:,:,25)
I know that I can do this with a for loop, but I am doing this inside of cvx sdp solver, where the variables are defined separately (and I can't run a for loop in an equality statement).
I have tried using bsxfun, but that doesn't work with symbolics (whether standard MATLAB symbolics, or cvx variables).
Some of my reading suggests repmat or arrayfun could provide solutions but I am unclear on how to use them in this situation.
  1 Comment
Sheng Cheng
Sheng Cheng on 17 Jan 2018
I have a similar question on the realization of such LMI expression in MALTAB. Have you figured out how to do it in MATLAB?

Sign in to comment.

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 4 May 2016
y=sym('y',[1,3])
A=randi(4,5,5,3)
out=zeros(size(A,1),size(A,2))
for k=1:size(A,3)
out=out+y(k)*A(:,:,k)
end

Walter Roberson
Walter Roberson on 17 Jan 2018
repmat(reshape(y,1,1,[]),size(A,1),size(A,2),1).*A

Tags

Products

Community Treasure Hunt

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

Start Hunting!