% % Matlab file for the solution of the final, Spring 2006 % % % test of the subroutine -- second test % n=5; k=3; a=[ 2.4154 0.9708 0.2140 0.4120 0.6833; 0.3050 2.9901 0.6435 0.7446 0.2126; 0.8744 0.7889 2.3200 0.2679 0.8392; 0.0150 0.4387 0.9601 2.4399 0.6288; 0.7680 0.4983 0.7266 0.9334 2.1338 ] % % compute the LU decomposition of the (incorrect) matrix a % [l u] = lu(a); % % suppose that the k-th column should be % akt = [ 0.6756 0.6992 0.7275 0.4784 0.5548 ]'; % % definition of the right-hand side % b= [0.1210 0.4508 0.7159 0.8928 0.2731 ]'; z=smartsolve(l,u,b,akt,k,n); a(:,k)=akt; sqrt(sum((a*z-b).^2)) z % % test of the subroutine -- second test % n=10; k=4; a=[ 2.9501 0.6154 0.0579 0.0153 0.8381 0.1934 0.4966 0.7271 0.7948 0.1365; 0.2311 2.7919 0.3529 0.7468 0.0196 0.6822 0.8998 0.3093 0.9568 0.0118; 0.6068 0.9218 2.8132 0.4451 0.6813 0.3028 0.8216 0.8385 0.5226 0.8939; 0.4860 0.7382 0.0099 2.9318 0.3795 0.5417 0.6449 0.5681 0.8801 0.1991; 0.8913 0.1763 0.1389 0.4660 2.8318 0.1509 0.8180 0.3704 0.1730 0.2987; 0.7621 0.4057 0.2028 0.4186 0.5028 2.6979 0.6602 0.7027 0.9797 0.6614; 0.4565 0.9355 0.1987 0.8462 0.7095 0.3784 2.3420 0.5466 0.2714 0.2844; 0.0185 0.9169 0.6038 0.5252 0.4289 0.8600 0.2897 2.4449 0.2523 0.4692; 0.8214 0.4103 0.2722 0.2026 0.3046 0.8537 0.3412 0.6946 2.8757 0.0648; 0.4447 0.8936 0.1988 0.6721 0.1897 0.5936 0.5341 0.6213 0.7373 2.9883 ]; % % compute the LU decomposition of the (incorrect) matrix a % [l u] = lu(a); % % suppose that the k-th column should be % akt = [ 0.5828 0.4235 0.5155 0.3340 0.4329 0.2259 0.5798 0.7604 0.5298 0.6405]'; % % definition of the right-hand side % b= [ 0.2091 0.3798 0.7833 0.6808 0.4611 0.5678 0.7942 0.0592 0.6029 0.0503]'; z=smartsolve(l,u,b,akt,k,n); a(:,k)=akt; sqrt(sum((a*z-b).^2)) z