How to compute the condition number of a problem efficiently? I know one can convert the matrix to dense and use numpy, but I am looking for something more efficient.
from fenics import *
import numpy as np
mesh = UnitIntervalMesh(10)
V = FunctionSpace(mesh, "Lagrange", 1)
u = TrialFunction(V)
v = TestFunction(V)
F = inner(v, u) * dx
A = assemble(lhs(F))
np.linalg.cond(A.array())
Nice! I was not patient enough to wait for the numpy result in your example . Is there some docs on the eigen solver? E.g. the following questions pop up:
What does the 1 in eigenSolver.solve(1) mean?
What is eigenSolver.parameters["spectrum"] about?
What do the zeros in eigenSolver.get_eigenvalue(0)[0] mean?
Also where can I read about PETScMatrix? e.g. what sparsity structure does it have and how do I linear algebra with it?
Also how to add a boundary condition before computing cond?
from fenics import *
import numpy as np
mesh = UnitIntervalMesh(10)
V = FunctionSpace(mesh, "Lagrange", 1)
u = TrialFunction(V)
v = TestFunction(V)
F = inner(v, u) * dx
A = assemble(lhs(F))
bc = DirichletBC(V, 1, "on_boundary")
bc.apply(A)
np.linalg.cond(A.array())
The SLEPcEigenSolver computes a partial spectrum. The “spetrum” argument lets you choose, which part of the spectrum should be computed. The eigenSolver.solve(1) means that roughly one eigenvalue should be computed. re, im = solver.get_eigenvalue(i) gives the real and imaginary part of the ith eigenvalue.