Skip to content

Commit

Permalink
Add NonnormalMeshgridAuto
Browse files Browse the repository at this point in the history
fixes #1
  • Loading branch information
André Gaul committed Mar 5, 2014
1 parent 290b26d commit 63f6c1e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pseudopy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-

from .nonnormal import NonnormalMeshgrid, NonnormalTriang, NonnormalPoints
from .nonnormal import NonnormalMeshgrid, NonnormalMeshgridAuto, \
NonnormalTriang, NonnormalPoints
from .normal import Normal, NormalEvals
from . import demo, utils

__all__ = ['NonnormalMeshgrid', 'NonnormalTriang', 'NonnormalPoints',
__all__ = ['NonnormalMeshgrid', 'NonnormalMeshgridAuto', 'NonnormalTriang',
'NonnormalPoints',
'Normal', 'NormalEvals',
'demo', 'utils']
28 changes: 28 additions & 0 deletions pseudopy/nonnormal.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,31 @@ class NonnormalPoints(NonnormalTriang):
def __init__(self, A, points, **kwargs):
triang = Triangulation(numpy.real(points), numpy.imag(points))
super(NonnormalPoints, self).__init__(A, triang, **kwargs)


class NonnormalMeshgridAuto(NonnormalMeshgrid):
'''Determines rough bounding box of pseudospectrum.
The bounding box is determined for a diagonalizable matrix via the
condition number of the eigenvector basis (see theorem 2.3 in the book
of Trefethen and Embree). Note that this method produces a bounding box
where the pseudospectrum with eps_max is guaranteed to be contained but
that the bounding box may be overestimated severely.
:param A: the matrix as numpy array with ``A.shape==(N,N)``.
:param eps_max: maximal value of :math:`\varepsilon` that is of interest.
'''
def __init__(self, A, eps_max, **kwargs):
from scipy.linalg import eig
evals, evecs = eig(A)

# compute condition number of eigenvector basis
kappa = numpy.linalg.cond(evecs, 2)

new_kwargs = {'real_min': numpy.min(evals.real) - eps_max*kappa,
'real_max': numpy.max(evals.real) + eps_max*kappa,
'imag_min': numpy.min(evals.imag) - eps_max*kappa,
'imag_max': numpy.max(evals.imag) + eps_max*kappa
}
new_kwargs.update(kwargs)
super(NonnormalMeshgridAuto, self).__init__(A, **new_kwargs)

0 comments on commit 63f6c1e

Please sign in to comment.