Path: news.mathworks.com!not-for-mail
From: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to make the function 'norm' treat its input as vectors?
Date: Thu, 14 Oct 2010 10:53:04 +0000 (UTC)
Organization: Universit&#228;t Heidelberg
Lines: 30
Message-ID: <i96neg$hsc$1@fred.mathworks.com>
References: <i938ok$smb$1@fred.mathworks.com> <i93kdo$o8f$1@fred.mathworks.com> <i94def$3h4$1@fred.mathworks.com> <i94mh3$9c3$1@fred.mathworks.com> <i94v8c$r8p$1@fred.mathworks.com> <i958vn$cjb$1@fred.mathworks.com> <i95ak3$srq$1@fred.mathworks.com>
Reply-To: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1287053584 18316 172.30.248.38 (14 Oct 2010 10:53:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 14 Oct 2010 10:53:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869888
Xref: news.mathworks.com comp.soft-sys.matlab:678377

Dear Matt J,
> > > norm(a) -> 0.003428
> > > sqrt(a*a.') -> 0.001468

> > Fine! What a pitty, that this does not work for arrays.

> It does! (See message 8).

It works, but the result is not the same and not what I expect as "norm":
  x = [1,2,3; 4,5,6]

  DNorm2(x, 1)
  >> 4.12  5.38  6.70

  sqrt(x' * x)
  >> 4.12  4.69  5.19
        4.69  5.38  6
        5.19  6       6.70

  DNorm2(x, 2)
  >> 3.74
        8.77

  sqrt(x * x.')
  >> 3.74  5.65
        5.65  8.77
  
Ok, you find the wanted values on the diagonal. But for N-dim arrays this fails and for larger arrays the waste of memory and the time for extracting the diagonal matters.

Kind regards, Jan