Operations for calculating l1 and Frobenius norm

Hi all,
Imagine I have 2 same-length vectors, u1 and u2, and e = u1 - u2. I'd like to calculate 1. l1 norm of e; 2. Frobenius norm of e. In my case I cannot get e and calculate norm directly, so I did something like this for Frobenius norm:
clear; clc;
% test norm 1 and Frobenius norm, what's the equivalent transformation?
u1 = (1:5)';
u2 = u1 - 3;
e = u1 - u2;
%%calculate Frobenius norm directly.
enm2 = norm(e, 'fro');
%%calculate Frobenius norm indirectly
emtx = [u1 -u2];
emtxt = emtx' * emtx;
enmts = sqrt(sum(emtxt(:)));
My question is, can I do something similar for calculating l1 norm? If I get emtx = [u1 -u2], IS there a way to calculate l1 norm without obtaining e = u1 - u2?
Many thanks!

Answers (1)

Matt J
Matt J on 12 Jul 2017
Edited: Matt J on 12 Jul 2017
Since it's a homework problem, I'll just give you a hint. What does
sum(emtx.^2,2)+2*prod(emtx,2)
give you?

7 Comments

Compare this to e= u1-u2
Can I extend this to random number of vectors? Such as emtx = [u1 -u2 u3 u4 -u5 ...]?
What is "e" for a random number of vectors?
Xh Du
Xh Du on 13 Jul 2017
Edited: Xh Du on 13 Jul 2017
e = u1 - u2 + u3 + u4 - u5 ...... It seems that for random number of vectors, the operation "sum(emtx.^2,2)+2*prod(emtx,2)" would require u1.*u1+u1.*u2+u1.*u3+...u5.*u4+u5.*u5 (I ignore the negative signs here), i.e. element-wise product between each 2 vectors. I might be able to write a for loop to do this with emtx (while emtx is the matrix contains all u vectors), but is there a better and simpler way (like eTe in Frobenius norm)?
Well, the Frobenius norm and the l1 norm are the same when the dimension of emtx is 1, so whatever you are doing for the Frobenius norm case can be done for the l1 case for each emtx(i). Then you can just add them up...
Hi Matt,
I understand that for the above case of 2 vectors, we can do "sum(emtx.^2,2)+2*prod(emtx,2)" to calculate l1 norm. But for more than 2 vectors, we can no longer simply use "sum(emtx.^2,2)+2*prod(emtx,2)", but need:
enm = u1.*u1 + u1.*u2 + u1.*u3 + u2.*u1 + u2.*u2 + u2.*u3 + u3.*u1 + u3.*u2 + u3.*u3
If for 3 vectors, I have
emtx = [u1 u2 u3];
How can I calculate 'enm' from 'emtx' without explicitly writing all the products and sum them?

Sign in to comment.

Categories

Asked:

on 12 Jul 2017

Commented:

on 13 Jul 2017

Community Treasure Hunt

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

Start Hunting!