Calculating divisions in matrices

1 visualización (últimos 30 días)
MarshallSc
MarshallSc el 17 de Jul. de 2021
Editada: Matt J el 17 de Jul. de 2021
If I have 8 different 10*10 matrices, for example as:
Ai=rand(10,10);
Aj=rand(10,10);
Ak=rand(10,10);
Al=rand(10,10);
Bi=rand(10,10);
Bj=rand(10,10);
Bk=rand(10,10);
Bl=rand(10,10);
I want to calculate the division of them in a way that, for example for the first row I would get:
C{(1,1):(1,4)}=[(Ai/Bi)/(Aj/Bk), (Ai/Bj)/(Ak/Bl), (Ai/Bk)/(Al/Bj), (Ai/Bl)/(Aj/Bk)]; %obviously the first component would be 1/(Aj/Bk)
In a way that I would get a 4*4 cell array as the final result that each cell contains a 10*10 matrix. The indexing is basically rolling around in the order of the field i,j,k,l. So I would get the following for the second row:
C{(2,1):(2,4)}=[(Aj/Bi)/(Ak/Bl), (Aj/Bj)/(Al/Bi), (Aj/Bk)/(Ai/Bj), (Aj/Bl)/(Aj/Bk)];
I basically want to, in each row, keep the first upper denominator constant as the corresponding dimension (2:j) and roll around the order of other dimensions for the other matrices.
I didn't simplify the equations into for example (Ai*Bl/Ak*Bj) to follow the indexing protocol (i through l). Can someone please help me with writing the code for this operation? I don't want to calculate them individually, can I use a for loop or a function to do this operation? Thank you!

Respuesta aceptada

Matt J
Matt J el 17 de Jul. de 2021
Editada: Matt J el 17 de Jul. de 2021
I don't quite understand how you sequence the combinations, but it will be something like the following:
Acell={Ai,Aj,Ak, Al};
Bcell={Bi,Bj,Bk, Bl};
p0=[1 2 3 4; 2 3 4 1; 3 4 1 2; 4 1 2 3 ].';
C=cell(4);
for i=1:4
p=p0;
p(p==i)=[];
p=reshape(p,3,4);
A=Acell(p);
B=Bcell(p);
for j=1:4
C{i,j}=(Acell{i}./B{1,j})./(A{2,j}./B{3,j});
end
end
C

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by