A matrix times a vector whose elements are matrix too.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Here, we use a matrix Sx times a vector initialvector whose elements are also matrix, the code is in the following. And we expect Sx*initialvector could give a matrix with size [5*5; 5*5; 5*5], similar with initialvector. What should we do?
Sx=1/sqrt(2)*[0 1 0; 1 0 1; 0 1 0];
initialu1=rand(5);
initialu0=rand(5);
initialuminus1=rand(5);
initialvector=[initialu1; initialu0; initialuminus1;];
Sx*initialvector
Added: Take a very simple example, if the elements initialu1, initialu0 and initialuminus1 are just scalar numbers, we calculate
ones(3)*initialvector
which should give
[initialu1+initialu0+initialuminus1; initialu1+initialu0+initialuminus1; initialu1+initialu0+initialuminus1]
However, initialu1, initialu0 and initialuminus1 are matrix here. But we still want the reslut
[initialu1+initialu0+initialuminus1; initialu1+initialu0+initialuminus1; initialu1+initialu0+initialuminus1]
which is a matrix now, and whose size is same with initialvector...
4 comentarios
Steven Lord
el 27 de Abr. de 2023
How do you get from:
% ones(3)*initialvector
to
% initialu1+initialu0+initialuminus1
Let's take a concrete example of an initial vector that contains scalars.
initialvector = [1; 2; 4];
result = ones(3)*initialvector
The result is a 3-by-1 vector, the same size as initialvector. Each element of result is the sum of the elements of initialvector, but how are you collapsing that vector to the scalar value resulting from summing the elements of initialvector?
And if we had a different matrix:
result2 = [0 1 0; 1 0 1; 0 1 0]*initialvector
How specifically would you collapse that vector into a scalar? Is the expected result 3, 5, 2, or something else entirely?
mean(result2)
max(result2)
min(result2)
result2(1)
Respuestas (1)
Steven Lord
el 27 de Abr. de 2023
a vector initialvector whose elements are also matrix
That doesn't exist in MATLAB, at least not if you want initialvector to be a numeric vector. Your initialvector isn't a vector, it's a matrix.
You could make a cell array that is a vector and have each cell in the cell array contain a matrix, but multiplication is not defined for cell arrays.
c = {magic(5), ones(5), rand(5)}
isvector(c)
Even if you used c and indexed into it to extract the matrices stored in each cell, matrix multiplication between a 3-by-3 matrix and a 5-by-5 matrix is not mathematically defined. But from the structure of that Sx matrix I wonder if maybe you're trying to do some type of convolution or filtering. If so conv2 or filter2 might be what you're looking for.
Sx=1/sqrt(2)*[0 1 0; 1 0 1; 0 1 0];
M = magic(5);
conv2(M, Sx, 'same')
Ver también
Categorías
Más información sobre Multidimensional Arrays 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!