MATLAB help, code for Frobenius norm

Click For Summary
SUMMARY

The discussion focuses on writing MATLAB code to compute the Frobenius norm of an mxn matrix A, defined mathematically as ||A||_{F} = √(∑_{i=1}^m ∑_{j=1}^n a^{2}_{i,j}). A user shared their initial code, which contained errors, specifically failing to initialize the sum variable before the loop and neglecting to compute the square root at the end. The correct approach involves initializing the sum variable outside the loop and ensuring the square root function is applied to the final sum.

PREREQUISITES
  • Understanding of MATLAB programming language
  • Familiarity with matrix operations in MATLAB
  • Knowledge of mathematical norms, specifically the Frobenius norm
  • Basic programming concepts such as loops and variable initialization
NEXT STEPS
  • Review MATLAB documentation on matrix operations
  • Learn about the MATLAB function for computing square roots, specifically 'sqrt'
  • Explore error handling in MATLAB to debug code effectively
  • Investigate performance optimization techniques for matrix computations in MATLAB
USEFUL FOR

Students, researchers, and professionals in mathematics, engineering, or computer science who are working with MATLAB and need to compute matrix norms efficiently.

tweety1234
Messages
111
Reaction score
0
Hello,

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

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

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
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K