trying to write matlab code for Frobenius norm of an mxn matrix

조회 수: 11 (최근 30일)
shelly
shelly 2013년 2월 23일
댓글: SARATHKUMAR 2025년 2월 14일
Hello, hoping someone can guide me, i asked my question on another forum, but realised this place could have better help,....with matlab, I have provided the link below, cause I cannot write the mathematical formula on here,
any help greatly appreciated.
the code i have written so far is
function w = frobeniusnorm(a,m,n) for i =1:m sm = 0 for j =1:n sm = sm+A(i,j)*a^2(i,j); end
which does not work
  댓글 수: 2
Muthu Annamalai
Muthu Annamalai 2013년 2월 23일
The problem with your code, Shelly, seems to be
function w = frobeniusnorm(a,m,n)
for i =1:m
sm = 0
for j =1:n
sm = sm+A(i,j)*a^2(i,j);
end
end
end
you have sm = 0, reinitialized every time. You need to move it out of the first for-loop.
A better solution without using the built-in norm() function is to write out sums,
sm = sqrt( sum(sum(A.^2)) )
I would strongly recommend you read the MATLAB tutorial on matrix indexing http://www.mathworks.com/help/matlab/math/matrix-indexing.html and use what is called 'vectorized code'
SARATHKUMAR
SARATHKUMAR 2025년 2월 14일
i need to find the Pulsatile velocity profile using frobenius method if any one have code for that please send on this question comment

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

답변 (3개)

Wayne King
Wayne King 2013년 2월 23일
Why not just use:
norm(X,'fro')
For example:
X = randn(8,8);
norm(X,'fro')

shelly
shelly 2013년 2월 23일
yeah I know this particular function,n but I have to first write the code and than compare my answers with matlab's built in function.

Rolando Molina
Rolando Molina 2018년 4월 13일
I think that this code was the original intention, and works:
function fn = frobenius_norm_mn_matrix(A,m,n) si=0; for i =1:m sj = 0; for j =1:n sj = sj+A(i,j)^2; end si=si+sj; end fn=sqrt(si) end

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by