How to sum 3d matrixes along the vector of the third dimension with symbolic variables ?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
In my code I try to sum vectors of a 3D matrix while having symbolic variables. I want to apply the sum to the vectors of the 3d dimension.
I tried the commande symsum( c (1,1,:)) but it's not working. Help me please.
Here is the code
syms r1;
syms r2;
syms r3;
syms r4;
c1= sym([r1 r2*(0.9239+0.3827*1i) -r1 -r2*(0.9239+0.3827*1i); r3 r1*(0.9239+0.3827*1i) -r3 -r1*(0.9239+0.3827*1i); 0 0 0 0; 0 0 0 0]);
c2= sym([r3 r1*(0.9239+0.3827*1i) -r3 -r1*(0.9239+0.3827*1i);0 0 0 0; r4 r2*(0.9239+0.3827*1i) -r4 -r2*(0.9239+0.3827*1i); 0 0 0 0]);
c3= sym([r2 r4*(0.9239+0.3827*1i) -r2 -r4*(0.9239+0.3827*1i);0 0 0 0; 0 0 0 0; r3 r1*(0.9239+0.3827*1i) -r3 -r1*(0.9239+0.3827*1i)]);
c4= sym([ 0 0 0 0; r1 r3*(0.9239+0.3827*1i) -r1 -r3*(0.9239+0.3827*1i); r2 r4*(0.9239+0.3827*1i) -r2 -r4*(0.9239+0.3827*1i);0 0 0 0]);
c5= sym([0 0 0 0; r4 r2*(0.9239+0.3827*1i) -r4 -r2*(0.9239+0.3827*1i);0 0 0 0; r1 r3*(0.9239+0.3827*1i) -r1 -r3*(0.9239+0.3827*1i)]);
c6= sym([0 0 0 0; 0 0 0 0; r1 r3*vpa(0.9239+0.3827*1i) -r1 -r3*(0.9239+0.3827*1i); r4 r2*(0.9239+0.3827*1i) -r4 -r2*(0.9239+0.3827*1i)]);
c=sym( cat(3,c1,c2,c3,c4,c5,c6));
ssent = sum(c,6);
For exemple ssent (1,1) is the sum of c1(1,1) with c2(1,1), c3(1,1), c4(1,1), c5(1,1) and c6(1,1).
Thank you.
0 comentarios
Respuestas (1)
Sameer
el 20 de Sept. de 2024
Hi Meriem
From my understanding, you want to sum the elements of a 3D symbolic matrix along the third dimension. Specifically, you want to sum each element at a given position across all the matrices stacked in the third dimension.
The "symsum" function is intended for symbolic summation with respect to a symbolic variable, which is not applicable for this use case. Instead, the "sum" function can be utilized to perform the summation across dimensions.
Here's how you can modify your code :
syms r1 r2 r3 r4;
c1 = sym([r1, r2*(0.9239+0.3827*1i), -r1, -r2*(0.9239+0.3827*1i);
r3, r1*(0.9239+0.3827*1i), -r3, -r1*(0.9239+0.3827*1i);
0, 0, 0, 0;
0, 0, 0, 0]);
c2 = sym([r3, r1*(0.9239+0.3827*1i), -r3, -r1*(0.9239+0.3827*1i);
0, 0, 0, 0;
r4, r2*(0.9239+0.3827*1i), -r4, -r2*(0.9239+0.3827*1i);
0, 0, 0, 0]);
c3 = sym([r2, r4*(0.9239+0.3827*1i), -r2, -r4*(0.9239+0.3827*1i);
0, 0, 0, 0;
0, 0, 0, 0;
r3, r1*(0.9239+0.3827*1i), -r3, -r1*(0.9239+0.3827*1i)]);
c4 = sym([0, 0, 0, 0;
r1, r3*(0.9239+0.3827*1i), -r1, -r3*(0.9239+0.3827*1i);
r2, r4*(0.9239+0.3827*1i), -r2, -r4*(0.9239+0.3827*1i);
0, 0, 0, 0]);
c5 = sym([0, 0, 0, 0;
r4, r2*(0.9239+0.3827*1i), -r4, -r2*(0.9239+0.3827*1i);
0, 0, 0, 0;
r1, r3*(0.9239+0.3827*1i), -r1, -r3*(0.9239+0.3827*1i)]);
c6 = sym([0, 0, 0, 0;
0, 0, 0, 0;
r1, r3*(0.9239+0.3827*1i), -r1, -r3*(0.9239+0.3827*1i);
r4, r2*(0.9239+0.3827*1i), -r4, -r2*(0.9239+0.3827*1i)]);
c = cat(3, c1, c2, c3, c4, c5, c6);
% Sum along the third dimension
ssent = sum(c, 3);
% Display the result
disp(ssent);
Hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Calculus 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!