MATLAB help, code for Frobenius norm

In summary, when computing the Frobenius norm of an mxn matrix A, it is important to initialize the sum before starting the loops and to take the square root at the end. This will ensure that the code works correctly.
  • #1
tweety1234
112
0
Hello,

I am trying to write a mtlab code to compute Frobenius norm of an mxn matrix A.

defined by
[tex] ||A||_{F} = \sqrt{ \sum_{i=1}^m \sum_{j=1}^n a^{2}_{i,j}} [/tex]

I have so far written this code, but it does not work, if anyone can help /guide me to the right path, would be greatly appreciated.

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
 
Physics news on Phys.org
  • #2
You need to initialize the sum before you start your loops, so put the 3rd line before the 2nd. Don't forget to take the square root at the end.
 

1. What is the Frobenius norm in MATLAB?

The Frobenius norm is a matrix norm that measures the size or magnitude of a matrix. It is often used to quantify the error between two matrices and can be calculated in MATLAB using the norm function with the parameter 'fro'.

2. How do I calculate the Frobenius norm of a matrix in MATLAB?

To calculate the Frobenius norm of a matrix in MATLAB, you can use the norm function with the parameter 'fro'. For example, if your matrix is stored in a variable A, you can use the command norm(A, 'fro') to calculate its Frobenius norm.

3. Can I use the Frobenius norm to compare two matrices in MATLAB?

Yes, the Frobenius norm can be used to compare two matrices in MATLAB. It measures the difference between the two matrices and can be interpreted as a measure of similarity. A lower Frobenius norm value indicates a higher similarity between the matrices.

4. How do I interpret the result of the Frobenius norm in MATLAB?

The result of the Frobenius norm in MATLAB is a single number that represents the size or magnitude of the matrix. It can be interpreted as the square root of the sum of squared elements in the matrix. This value can be used to compare matrices or to measure the error between two matrices.

5. Can I use the Frobenius norm in MATLAB for non-square matrices?

Yes, the Frobenius norm can be used for both square and non-square matrices in MATLAB. It is a general matrix norm that is applicable to matrices of any size and shape. However, it is important to note that the Frobenius norm may not be the most appropriate norm for non-square matrices, and other norms may be more suitable depending on the application.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
891
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
815
  • Engineering and Comp Sci Homework Help
Replies
1
Views
970
  • Engineering and Comp Sci Homework Help
Replies
2
Views
829
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
21
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top