JuliaLinearAlgebra / IterativeSolvers.jl

Iterative algorithms for solving linear systems, eigensystems, and singular value problems
MIT License
399 stars 105 forks source link

Problem with Sor #232

Closed ChrisNabold closed 5 years ago

ChrisNabold commented 5 years ago

I tried to setup a small problem using sor for an linearequation. Can you please show me how I set up this example: sorError.txt Thank you

amontoison commented 5 years ago

@ChrisNabold, with sor you need to give A as a dense matrix. In you case you gave a sparse one.

sor(Matrix(A), b, 1.4)

should work fine.

haampie commented 5 years ago

A should be sparse if it is! There's an optimized implementation for sparse matrices.

The issue of op is that b is sparse (maybe it could be, but x won't be sparse anyways, so IterativeSolvers expects dense vectors).

using SparseArrays, LinearAlgebra
A = sprand(100, 100, 0.1)
A = A + A' + 100I
b = A * ones(100)
x = sor(A, b, 1.3, maxiter = 10)

Also note that the stationary methods do not have a stopping criterion in terms of a residual being small, because that would be extra overhead (the idea being that stationary methods would go into a multigrid method or so, where you just do one or two iterations). So you have to set maxiter to something sensible!