Jeremy Knight Math 639
<Text-field style="Heading 1" layout="Heading 1">Algorithm 7.3: SOR_iterate(n,A,b,x_0,omega,tol,N,display)</Text-field> SOR_iterate := proc(n,A,b,x_0,omega,tol,N,display) #n: scalar number of equations and unknown; #A: Coefficient Matrix #b: Constant Vector #XO: Initial approximation vector #omega: SOR parameter #tol: tolerance #N: Max iterations local i, j, k, m, tempx, T, X0, x_k, DX, euclid_norm; #option trace; #initialize a matrix of vectors to store the iterates X0:=Matrix(); X0(1,1):=x_0; k:=1; while k <= N do #initialize a temporary vector to store the approximation values during the loop tempx:=Vector(); #retrieve vector x_k from X0 matrix x_k:=X0(1,k); if display=1 then print(k-1,evalf(X0(1,k))); end if; for i from 1 to n do T:=0: for j from 1 to i-1 do T:=T+(A(i,j)*tempx(j)): end do: for j from i+1 to n do T:=T+(A(i,j)*x_k(j)): end do: tempx(i):=(1-omega)*x_k(i) + (1/(A(i,i)))*(omega*(-1*T+b(i))): end do: X0(1,k+1):=tempx: Print(X0(1,k+1)); #Calculate the norm of ||x_(k+1)-x_k|| DX:=abs(X0(1,k) - X0(1,k+1)); euclid_norm:=DX(1); for m from 2 to n do if DX(m)>euclid_norm then euclid_norm:=DX(m); end if; end do; #Compare Euclidean Norm to tolerance if euclid_norm < tol then print("tolerance reached Iterations =",k); print(evalf(X0(1,k+1))); break; end if; if k>N then break; end if; k:=k+1; end do; if k=N+1 then print("tolerance not reached"); print(evalf(X0(1,k))); end if; end proc:
A:=Matrix([[4,3,0],[3,4,-1],[0,-1,4]]): b:=Vector([24,30,-24]): x:=Vector([1,1,1]): SOR_iterate(3,A,b,x,1.25,10^(-10),40,1); NiQiIiEtJkknVmVjdG9yRzYkJSpwcm90ZWN0ZWRHSShfc3lzbGliRzYiNiNJJ2NvbHVtbkdGKjYjL0kkJWlkR0YqIiojZiIpPUQ= NiQiIiItJkknVmVjdG9yRzYkJSpwcm90ZWN0ZWRHSShfc3lzbGliRzYiNiNJJ2NvbHVtbkdGKjYjL0kkJWlkR0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