ITADN

error in CG with Preconditioner

#332ClosedChrisNabold 创建于 2023-02-17
C
ChrisNaboldcommented
I tried to run Example 8.8.3 from the book T. A. Driscoll, R. J. Braun Fundamentals of Numerical Computation Julia Edition. Whereas cg without preconditioner seems to work, I receive an error message when using cg with a preconditioner. ![2023-02-17_14-53-53](https://user-images.githubusercontent.com/17845732/219674755-ded03843-13ec-4bee-aabc-b9938b5ce504.png) using MAT, LinearAlgebra, SparseArrays, IterativeSolvers, Preconditioners file = matopen("A.mat"); A = read(file,"A"); close(file); n = size(A,1); @show n,nnz(A) b = ones(n); M = DiagonalPreconditioner(diag(A)); plain(b) = cg(A,b,maxiter=200,reltol=1.e-4,log=true) time_plain = @elapsed x,hist1 = plain(b) prec(b) = cg(A,b,P1=M,maxiter=200,reltol=1.e-4,log=true) time_prec = @elapsed x,hist2 = prec(b) @show time_plain, time_prec rr = hist1[:resnorm] plot(0:length(rr),rr/rr[1],yscale=:log10,label="plain") rr = hist2[:resnorm] plot!(0:length(rr),rr/rr[1],yscale=:log10,label="preconditioned") title!("Diagonal preconditioning in CG") ![2023-02-17_14-53-53](https://user-images.githubusercontent.com/17845732/219675049-d4929a60-064f-4418-abff-d1ad12c2d021.png)
关闭于 2023-02-20 1 条评论