Please guide on how to calculate the opnorm for p=2 in julia for sparse matrices. When I try I get the error
ArgumentError: 2-norm not yet implemented for sparse matrices. Try opnorm(Array(A)) or opnorm(A, p) where p=1 or Inf.
My code:
using SparseArrays
using LinearAlgebra
# Define a sparse matrix
A = sparse([1, 2], [1, 2], [1.0, 5.0], 2, 2)
# Calculate the 2-norm operator norm (default)
opnorm_value = opnorm(A)
Do you want the actual opnorm or are you OK with an approximation? The reason it isn’t implemented is that the 2 norm is usually computed with an SVD which would be really slow for sparse matrices.
In particular, the operator 2-norm \Vert A \Vert_2 is exactly equal to the largest singular value of A. For a large sparse matrix (or a matrix implicitly defined as a linear operator), you need to compute this by iterative methods, which are not included in SparseArrays but are provided by many packages.
For example, you can use KrylovKit.svdsolve(A)[1][1] from KrylovKit.jl to get the largest singular value of a sparse matrix A, equivalent to the operator norm.