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.

답변 (1개)

Torsten
Torsten 2023년 10월 22일
이동: Torsten 2023년 10월 22일

0 개 추천

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

댓글 수: 7

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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2023년 10월 22일

편집:

2023년 10월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by