Hello all, I am trying to find Frobenius norm of each column of 2 X 500 matrix in MATLAB but not getting it correctly.
Any help in this regard will be highly appreciated.

Réponses (1)

Torsten
Torsten le 22 Oct 2023
Déplacé(e) : Torsten le 22 Oct 2023

0 votes

From the documentation:
n = norm(X,"fro") returns the Frobenius norm of matrix or array X.

7 commentaires

chaaru datta
chaaru datta le 22 Oct 2023
Thank u sir for the answer...but I want to find the norm of each column of X.
Torsten
Torsten le 22 Oct 2023
Modifié(e) : Torsten le 22 Oct 2023
rng("default")
X = rand(3);
n = arrayfun(@(i)norm(X(:,i),"fro"),1:size(X,2))
n = 1×3
1.2249 1.1152 1.1373
n = vecnorm(X,2)
n = 1×3
1.2249 1.1152 1.1373
Dyuman Joshi
Dyuman Joshi le 22 Oct 2023
Modifié(e) : Dyuman Joshi le 22 Oct 2023
Since frobenius norm is defined as the square root of sum of the absolute squares of elements of an array, simply calculate it directly for each column -
y = rand(2,500);
sqrt(sum(abs(y).^2))
ans = 1×500
1.0265 0.8084 1.1542 0.5197 0.5827 1.0240 0.0890 1.3322 1.0956 0.4976 0.7836 0.1435 0.3630 0.7378 0.7803 1.0122 0.8657 0.8241 1.1077 0.2674 0.5666 0.6570 0.2569 0.8938 0.3199 1.0291 0.7741 0.4520 0.2461 1.0370
or use vecnorm -
vecnorm(y,2)
ans = 1×500
1.0265 0.8084 1.1542 0.5197 0.5827 1.0240 0.0890 1.3322 1.0956 0.4976 0.7836 0.1435 0.3630 0.7378 0.7803 1.0122 0.8657 0.8241 1.1077 0.2674 0.5666 0.6570 0.2569 0.8938 0.3199 1.0291 0.7741 0.4520 0.2461 1.0370
Torsten
Torsten le 22 Oct 2023
"abs" seems to be superfluous.
Dyuman Joshi
Dyuman Joshi le 22 Oct 2023
Modifié(e) : Dyuman Joshi le 22 Oct 2023
It might be, but that's how Wikipedia and Wolfram Alpha define it.
Idk why though.
Torsten
Torsten le 22 Oct 2023
Modifié(e) : Torsten le 22 Oct 2023
For complex matrices most probably.
Dyuman Joshi
Dyuman Joshi le 22 Oct 2023
That should be it.
For someone who has worked with real valued data only, it easily escapes my mind that people work with non-real valued data as well.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by