Related to Frobenius norm

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.

Answers (1)

Torsten
Torsten on 22 Oct 2023
Moved: Torsten on 22 Oct 2023
From the documentation:
n = norm(X,"fro") returns the Frobenius norm of matrix or array X.

7 Comments

Thank u sir for the answer...but I want to find the norm of each column of X.
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
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
"abs" seems to be superfluous.
Dyuman Joshi
Dyuman Joshi on 22 Oct 2023
Edited: Dyuman Joshi on 22 Oct 2023
It might be, but that's how Wikipedia and Wolfram Alpha define it.
Idk why though.
Torsten
Torsten on 22 Oct 2023
Edited: Torsten on 22 Oct 2023
For complex matrices most probably.
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.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 22 Oct 2023

Edited:

on 22 Oct 2023

Community Treasure Hunt

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

Start Hunting!