Opened 15 years ago

Closed 15 years ago

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

Reported by: Owned by: William Stein William Stein major sage-2.10.1 linear algebra N/A

### 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 15 years ago by William Stein

Type: defect → enhancement

### comment:2 Changed 15 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 15 years ago by jkantor

In the above example it should be

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

### comment:4 Changed 15 years ago by Alex Ghitza

Milestone: sage-2.10.1 → sage-2.10 add p-norm as a method to vectors (probably very easy) → [with patch] add p-norm as a method to vectors (probably very easy)

### comment:5 Changed 15 years ago by Harald Schilly

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

### comment:6 Changed 15 years ago by William Stein

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

### comment:7 Changed 15 years ago by Alex Ghitza

Summary: [with patch] add p-norm as a method to vectors (probably very easy) → [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 15 years ago by Robert Miller

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

### comment:9 Changed 15 years ago by Michael Abshoff

Resolution: → fixed new → closed

Merged in Sage 2.10.1.alpha0

Note: See TracTickets for help on using tickets.