Opened 12 years ago

Closed 12 years ago

# [with patch, positive review] add p-norm as a method to vectors (probably very easy)

Reported by: Owned by: was was major sage-2.10.1 linear algebra

### Description

```
On Jan 10, 2008 12:17 AM, vgermrk <vgermrk@googlemail.com> wrote:
>
> [Sorry for asking so much "Is there a ... function in Sage?" -
> Questions.]
>
> But: Is there a native way to compute the p-Norm (e.g. euclidean oder
> maximum norm) of a vector?
>

There is no built in function, but we can write one easily:

def pnorm(v, p):
return sum([a^p for a in v])^(1/p)

Then:

sage: pnorm(vector([1,2,3]), 5)
276^(1/5)
sage: pnorm(vector(RDF, [1,2,3]), 5)
3.07738488539
sage: var('a b c d p')
sage: pnorm(vector([a, b, c, d]), p)
(d^p + c^p + b^p + a^p)^(1/p)

-- William
```

### comment:1 Changed 12 years ago by was

• Type changed from defect to enhancement

### comment:2 Changed 12 years ago by jkantor

for RDF and CDF vectors

```from numpy import linalg
v=vector(RDF,[1,2,3])
linalg.norm(v,5)
```

3.0773848853940629

### comment:3 Changed 12 years ago by jkantor

In the above example it should be

`linalg.norm(v.numpy(),5)`

### comment:4 Changed 12 years ago by AlexGhitza

• Milestone changed from sage-2.10.1 to sage-2.10
• Summary changed from add p-norm as a method to vectors (probably very easy) to [with patch] add p-norm as a method to vectors (probably very easy)

### comment:5 Changed 12 years ago by schilly

does this also work for matrices? matrix norms are at least equally important!

### comment:6 Changed 12 years ago by was

What is the defn of matrix p-norms? Is it the same?

### comment:7 Changed 12 years ago by AlexGhitza

• Summary changed from [with patch] add p-norm as a method to vectors (probably very easy) to [with patch, needs review] add p-norm as a method to vectors (probably very easy)

I agree that matrix norms are important. However, unlike the case of vectors, where the p-norm is rather universally agreed upon, there are a bunch of different definitions for norms on matrices, see http://en.wikipedia.org/wiki/Matrix_norm There are at least 3 different things denoted as p-norm there.

I think it's important for us to do this, but trickier than the vector case, so I've made it into track #1763.

In the meantime, it would be great if someone reviewed the current patch.

### comment:8 Changed 12 years ago by rlm

• Summary changed from [with patch, needs review] add p-norm as a method to vectors (probably very easy) to [with patch, positive review] add p-norm as a method to vectors (probably very easy)

### comment:9 Changed 12 years ago by mabshoff

• Resolution set to fixed
• Status changed from new to closed

Merged in Sage 2.10.1.alpha0

Note: See TracTickets for help on using tickets.