Section.: E ; AP, Section.: E,,; AP,,, Section. Homework solutions. Consider the two upper-tringulr mtrices: b b b A, B b b. b () Show tht their product C = AB is lso upper-tringulr. The product is b b b b b b C AB b b b, b which is upper-tringulr. (b) Let A nd B be two n by n upper-tringulr mtrices. Show tht their product is lso upper tringulr. If A nd B re upper-tringulr, then ij, b ij = if i > j. The element in the ith row, jth column of the product C = AB is c ij n k ik b kj k i The ik terms in the first sum on the RHS re ll zero since i > k. If i > j, then in the second sum k i > j, so ll the b kj terms re zero. Therefore, the entire sum is zero when i > j, nd C is upper-tringulr. ik b kj ki ik b kj.
Algorithms nd Progrms. Construct forwrd substitution lgorithm to solve the liner system AX = B when A is lower-tringulr. function X=forsub(A,B) %Input - A is n n n lower-tringulr nonsingulr mtri % - B is n n mtri %Output - X is the solution to the liner system AX = B %Find the dimension of B nd initilize X n=length(b); X=zeros(n,); X()=B()/A(,); for k=:n X(k)=(B(k)-A(k,:(k-))*X(:(k-)))/A(k,k); end. Use forsub to solve the system LX = B, where i j i j l ij, nd b i = i. i j The result of forsub(l,b) is X = (.,.,.,.,.77,.78,.8,.,.7,.77,.888,.7787,.8,.,.8,.,.7,.77877,.778.8)
Section. nd : Show tht AX = B is equivlent to the upper-tringulr system UX = Y, nd find the solution.. Subtrct ½ times the st row from the second, nd ½ times the st row from the rd to get 7 Subtrct / times the nd row from the rd to get UX = Y. Solving this system by bcksubstitution yields = -, =, =... Subtrct times the first row from the nd, times the st row from the th to get Subtrct - times the nd row from the rd nd times the nd row from the th to get 7 Subtrct -7/ times the rd row from the th nd multiply the th row by to get UX = Y. Solving this system by bck-substitution yields =, =, =, = -.
. () Solve AX = B, where A is the by Hilbert mtri ij = /(i+j-) nd B = (,,, ). Gussin elimintion yields =, = -, =, = -. (b) Now solve AX = B using four digit rithmetic nd the pproimte Hilbert mtri........ A....7...7. Solving by Gussin elimintion using digit rithmetic yields = 8.7, = -., =., = -8..
Algorithms nd Progrms. Construct progrm tht will solve tridigonl system of the form d + c = b + d + c = b + d + c = b. N- N- + d N- N- + c N- N = b N- N- N- + d N N = b N Assume tht row interchnges re not needed nd tht row k cn be used to eliminte k in row k+. The tridigonl system cn be solved with the stndrd Gussin elimintion lgorithm. But, it cn be solved much more efficiently if we use the fct tht t the pth step, only one term, p+,p p needs to be eliminted. The bck-substitution lgorithm cn lso be mde more efficient if we use the fct tht fter upper-tringulriztion, only elements on the digonl nd one step bove it re non-zero. The following is n emple of code tht does Gussin elimintion on the tridigonl system. Note tht this cn be mde even more efficient if we store only the digonl nd off-digonl elements insted of the entire mtri A. function X = tridig(a,b) %Input - A is n N N tri-digonl mtri % - B is n N mtri %Output - X is n N mtri contining the solution to AX=B. %Initilize X nd the temporry storge mtri C [N N]=size(A); X=zeros(N,); C=zeros(,N+); %Form the ugmented mtri: Aug=[A B] Aug=[A B]; for p=:n- %Elimintion process for column p m=aug(p+,p)/aug(p,p); Aug(p+,p:N+)=Aug(p+,p:N+)-m*Aug(p,p:N+); end %Bck Substitution on [U Y] using Progrm. X=bcksubtridig(Aug(:N,:N),Aug(:N,N+)); function X=bcksubtridig(A,B) %Input - A is n n n nonsingulr mtri with non-zero elements % on the digonl nd the k,k+ entries % - B is n n mtri %Output - X is the solution to the liner system AX = B %Find the dimension of B nd initilize X n=length(b); X=zeros(n,); X(n)=B(n)/A(n,n); for k=n-:-: X(k)=(B(k)-A(k,k+)*X(k+))/A(k,k); end
. Use the Gussin elimintion progrm with prtil pivoting to solve the system AX = B, where ij = i j-, b =, nd b i = (i N )/(i ) for i >. The ect solution is X = (,,,,). Eplin ny devitions from the ect solution. The uptrbk progrm produces the ect solution for N= nd N=7. When N =, it produces.7.8877.7.77. X.787.8.7..87.88 which hs miml error of.7e-. The error results from roundoff when lrge numbers re dded to smll numbers. This occurs when elements below the pivot re much lrger thn the elements in the corresponding row. When N is smll, this error is smll, since the difference between row elements is not too lrge. But s N increses, this difference increses, nd prtil pivoting lone will led to errors.. Construct progrm tht chnges the pivoting strtegy in the Gussin elimintion progrm to scled prtil pivoting. In scled prtil pivoting, t step p we interchnge the pivot row with the row below it tht hs the miml rtio of kp to the lrgest element in the kth row. This cn be implemented by replcing the following lines in the uptrbk code % Prtil pivoting for column p [Y,j]=m(bs(Aug(p:N,p))); with these: % Scled prtil pivoting for column p s=zeros(n-p+,); for k=p:n s(k-p+) = min(bs(aug(k,p)./aug(k,p+:n))); end; [Y,j]=m(s); It first loops through rows p to N to find the rtios of kp to the miml element in row k, then finds the row with the miml such rtio.. Use your scled prtil pivoting progrm from Problem to solve the system given in Problem for N =. Eplin ny improvements in the solution.
The scled prtil pivoting strtegy produces the ect solution when N =. The reson the scled prtil pivoting strtegy does better is tht it voids s much s possible subtrcting smll numbers from much lrger numbers. Note tht Mtlb s built in liner solver A\B produces the solution.87.887.88.878.8878 X.87.8.788..8.7 which hs miml error of.7e-. The scled prtil pivoting scheme does better thn Mtlb s solver.