MATLAB help, code for Frobenius norm

Click For Summary
To compute the Frobenius norm of an mxn matrix A in MATLAB, the formula used is ||A||_{F} = √(∑(i=1 to m) ∑(j=1 to n) a_{i,j}^2). The user shared their initial code but encountered issues with its functionality. Key suggestions include initializing the sum variable before the loops and ensuring the square root is calculated at the end of the function. Properly structuring the code is essential for accurate computation. Following these guidelines will help achieve the desired result.
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.
 
Greetings to all, I am writing with a question regarding graph generation in LTSpice. I am using LTSpice XVII and am trying to plot AM-AM and AM-PM characterization for a power amplifier, but I haven't been successful yet, likely due to my lack of practice with this specific analysis. I have been using a square wave input at 8.2 MHz as the voltage waveform for my power amplifier. It is said that for a switching amplifier like Class-D, the AM-AM / AM-PM (amplitude-to-amplitude and...

Similar threads