How to fastly calculate this matrix operation
Mostra commenti meno recenti
A matrix μ is a
dimensional matrix, p is a
dimensional vector, q is a
dimensional matrix, c is a constant.
How to fastly calculate the following three dimensional (
) matrix X, where the
element in X is
4 Commenti
Rik
il 9 Lug 2024
Let's start at the beginning: how would you write the slow code that does this? You can even start with random data:
K=10;
J=12;
I=14;
c=rand;
mu = rand(K,J);
p = rand(K,1);
q = rand(K,I);
John D'Errico
il 9 Lug 2024
Unless I==J, then your expression does not even make mathematical sense. That is, you tell us that q is KxI, but then you index it as q(r,j), where r varies from 1 to K. Even then, you seem to be confusing I and J.
Next, the numerator has the shape of a vector, possibly of length either J or I, this is not clear. But the denominator is a 3 dimensional thing.
I would STRONGLY suggest that you need to use different variables than I and J here, as I think even you have become confused in what you wrote yourself.
Honestly, I'm not even sure how I would write that were I to use loops.
That is, you tell us that q is KxI, but then you index it as q(r,j), where r varies from 1 to K.
It's indexed q(r,i).
Next, the numerator has the shape of a vector, possibly of length either J or I, this is not clear. But the denominator is a 3 dimensional thing.
I think numerator and denominator are just scalars.
John D'Errico
il 9 Lug 2024
Sorry. Bad eyesight on my part. it is q(r,i). I thought that was a j. Again, the problem with using I and J. is they are easily confused.
As far as the denominator being a scalar, you can also view it as a 3-dimensional array, of the same shape as X. And I think, as you (@Torsten) knows, that is how you would perform the computation.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!