# L-11 MCS 471 Fri 16 Sep 2022 : runsor.jl # Interactive running of successive over-relaxation on a test system. import Random # to fix the seed of the random numbers include("sor.jl") """ Returns a special matrix. """ function special_matrix() mat = [ 3.0, -1.0, 0.0, 0.0, 0.0, 0.5, -1.0, 3.0, -1.0, 0.0, 0.5, 0.0, 0.0, -1.0, 3.0, -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 3.0, -1.0, 0.0, 0.0, 0.5, 0.0, -1.0, 3.0, -1.0, 0.5, 0.0, 0.0, 0.0, -1.0, 3.0] mat = reshape(mat, (6, 6)) mat = permutedims(mat) return mat end """ Runs the successive over-relaxation on a special matrix. """ function main() mat = special_matrix() dim = 6 sol = ones(dim, 1) rhs = mat*sol Random.seed!(123) noise = 1.0e-4*rand(dim, 1) wrk = sol + noise println("The matrix :") show(stdout, "text/plain", mat); println(""); println("The right hand side :") show(stdout, "text/plain", rhs); println(""); sol, numit, nrmdx, fail = sor(mat, rhs, wrk) println("The solution after ", numit, " iterations :") for i=1:dim strsol = @sprintf("%.16e", sol[i]) println(i, " : $strsol") end print("Estimated forward error : ", nrmdx) if fail println(" failed.") else println(" succeeded.") end end main()