# L-11 MCS 471 Fri 16 Sep 2022 : runjacobi.jl # Interactive running of the method of Jacobi on a test system. import Random # to fix the seed of the random numbers include("jacobi.jl") """ Prompts the user for a dimension and then generates a random matrix to test the Jacobi method. """ function main() print("Give the dimension : ") line = readline(stdin) dim = parse(Int, line) Random.seed!(123); mat = rand(dim, dim) # make the matrix diagonally dominant for i=1:dim mat[i, i] = 100*mat[i,i] end sol = ones(dim, 1) noise = 1.0e-4*rand(dim, 1) rhs = mat*sol wrk = sol + noise println("A random matrix :") show(stdout, "text/plain", mat); println(""); sol, numit, nrmdx, fail = jacobi(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()