Calculation with three dimensional matrices

I want to calculate a vector , with each element defined as follows
, where is the set of N dimensional vector, and is also the set of N dimensional vector, c is a constant. The superscript T is denoted as the transpose operation.
In my matlab code, is stored as a three dimensional matrix G, its dimension is (where ).
is also stored as a three dimensional matrix W, its dimension is (where ). c is a scalar.
I know i can use multiple for loop to calculate this vector Y, but it is too inefficient. Is there any some fast way to calculate it, maybe use three-dimensional matrix calculation method?

9 Kommentare

Matt J
Matt J am 18 Jan. 2025
Isn't supposed to represent a scalar product? If so, why do you have a subscript of 2 in as if you are taking l2-norm of a vector?
Hancheng Zhu
Hancheng Zhu am 19 Jan. 2025
oh,i make a mistake, it is just a absolute value of this complex scalar, let me revise it.
埃博拉酱
埃博拉酱 am 21 Jan. 2025
Bearbeitet: Torsten am 21 Jan. 2025
g是矩阵,不是个标量吗?你对标量做转置是什么意思?我感觉你写的公式还是有问题,不如直接上代码……
g is a matrix, not a scalar? What do you mean by transposing a scalar? I feel that there is still something wrong with the formula you wrote. It is better to go directly to the code...
Torsten
Torsten am 21 Jan. 2025
is an N-dimensional vector.
埃博拉酱
埃博拉酱 am 21 Jan. 2025
Bearbeitet: 埃博拉酱 am 21 Jan. 2025
@Torsten Then he is transposing a 1×1×N vector (since G is K×J×N). I don't think transposition is well-defined for a vector on dimension 3.
Torsten
Torsten am 21 Jan. 2025
It's just a formal mathematical description of what should be coded. In the code, g_(k,j) and w_(k,i) must be of size (N,1).
埃博拉酱
埃博拉酱 am 21 Jan. 2025
@Torsten I've always felt that mathematical formulas are far less expressive than program code. Many of the symbolic representations are rudimentary, crude, and ambiguous. Shortness is perhaps its only "advantage" - which is often criticized in program code for sacrificing readability.
Torsten
Torsten am 21 Jan. 2025
I've made the opposite experience.
Imagine you have code for the computation of Y_i. I would be really surprised if it were easier to read than the mathematical formula from above.
Paul
Paul am 21 Jan. 2025
Perhaps you should post the code that you have along with sample input data.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

埃博拉酱
埃博拉酱 am 22 Jan. 2025

0 Stimmen

If your formula expresses what @Torsten understands, I'll code like this:
function Y=cGW_Y(c,G,W)
Y=permute(pagemtimes(permute(G,[2,3,1]),permute(W,[3,2,1])),[4,3,2,1]);%1×K×I×J
Y=pagemtimes(Y,'none',Y,'ctranspose');%1×1×I×J
Y=log2(sum(Y./(sum(Y,3)+c*c-Y),4)+1);%1×1×I
end

Weitere Antworten (1)

Divyanshu
Divyanshu am 21 Jan. 2025

0 Stimmen

You can try using 'pagetimes' function of MATLAB. For more details about 'pagetimes' refer the following documentation link:
Additionally, you can take reference from following MATLAB answer thread as well:
Hope it helps!

Kategorien

Produkte

Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by