Array of Matrices multiplication
43 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hugo Hernández Hernández
el 9 de Dic. de 2020
Comentada: Hugo Hernández Hernández
el 9 de Dic. de 2020
Solving an exercise for orbital mechanics I found a problem while multiplying a 3x3 matrix by a 3x1 Matrix, actually these matrices have 1442 values so first one is 3x4326 and second one is 3x1442. First array is a vector of 3x3 matrices but I do not know how to separate each matrix and then multiply them by my 3x1 array of matrices. I have tried with a for loop, or by selecting the arrays or columns and then compute the operation but that did not work. The full code is very large and has other .m files involved so I am attaching the specific lines with the problem:
%% Position
R3_Thot = [cos(Tho_t), sin(Tho_t), z_0; -sin(Tho_t), cos(Tho_t), z_0; z_0, z_0, z_1];
%%% 3x3 array of matrices with 3x4326 length
%%% R_p1 is an array of 3x1 matrices with a 3x1442 length
Rpos_Efix1 = R3_Thot*R_p1; %%% I want to perform this operation but I got errors like size mismatching
I tried also with .* operator but does not work, and I am not sure how to solve or compute them using a for loop.
Respuesta aceptada
Adam Danz
el 9 de Dic. de 2020
Editada: Adam Danz
el 9 de Dic. de 2020
One way to approach this is to break up the 3x4326 matrix into a 3x3x1442 array.
data = rand(3,4326); % 3x4326 matrix
dataArray = reshape(data,3,3,size(data,2)/3);
size(dataArray)
vec = [1;2;3];
z = pagemtimes(dataArray, vec);
size(z)
For releases prior to Matlab r2020b, you can set up a loop
vec = [1;2;3];
z = nan(3,1,size(dataArray,3));
for i = 1:size(dataArray,3)
z(:,:,i) = dataArray(:,:,i) * vec;
end
size(z)
3 comentarios
Adam Danz
el 9 de Dic. de 2020
To reduce the 3x1x1442 array to a 3x1442 matrix use,
m = reshape(z,3,[]);
or see squeeze().
Más respuestas (0)
Ver también
Categorías
Más información sobre Satellite and Orbital Mechanics 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!