diff --git a/mp5/Project_5_Maggioni_Claudio.pdf b/mp5/Project_5_Maggioni_Claudio.pdf index f78ea03..2bf0dc0 100644 Binary files a/mp5/Project_5_Maggioni_Claudio.pdf and b/mp5/Project_5_Maggioni_Claudio.pdf differ diff --git a/mp5/Project_5_Maggioni_Claudio.tex b/mp5/Project_5_Maggioni_Claudio.tex index a569b90..e20018e 100644 --- a/mp5/Project_5_Maggioni_Claudio.tex +++ b/mp5/Project_5_Maggioni_Claudio.tex @@ -127,6 +127,9 @@ My implementation is in the file \texttt{deblurring.m}. Plots for the original i from the two conjugate gradient functions over the iteration count can be found respectively in figure \ref{fig:orig}, \ref{fig:mycg}, \ref{fig:pcg}, and \ref{fig:rvec}. +As a terminating condition for the \texttt{myCG} implementation, I chose to check if the residual divided by the 2-norm of +$b$ is less than the given tolerance. This mimicks the behaviour of MATLAB's \texttt{pcg} to allow for a better comparison. + \begin{figure}[h] \begin{subfigure}{0.33\textwidth} \centering diff --git a/mp5/Project_5_Maggioni_Claudio/deblurring.m b/mp5/Project_5_Maggioni_Claudio/deblurring.m index 5b5ad1d..979bd21 100644 --- a/mp5/Project_5_Maggioni_Claudio/deblurring.m +++ b/mp5/Project_5_Maggioni_Claudio/deblurring.m @@ -26,7 +26,7 @@ bt = A' * b; IL = ichol(AT, struct('type', 'nofill', 'diagcomp', 0.01)); [x, rvec] = myCG(AT, bt, zeros(size(b)), 200, 1e-6); -[x2, ~, ~, ~, rvec2] = pcg(AT, bt, 1e-6, 200, IL, IL'); +[x2, flag, ~, ~, rvec2] = pcg(AT, bt, 1e-6, 200, IL, IL'); X2 = zeros(250, 250); for i = 0:249 diff --git a/mp5/Project_5_Maggioni_Claudio/myCG.m b/mp5/Project_5_Maggioni_Claudio/myCG.m index d014642..4bb976d 100644 --- a/mp5/Project_5_Maggioni_Claudio/myCG.m +++ b/mp5/Project_5_Maggioni_Claudio/myCG.m @@ -17,7 +17,7 @@ function [x,rvec] = myCG(A, b, x0, max_itr, tol) delta_old = delta_new; rvec(i + 1) = delta_new; - if delta_new < tol + if delta_new / norm(b) < tol rvec = rvec(1:i+1); break end diff --git a/mp5/img_my-1.png b/mp5/img_my-1.png index dbf68b4..ea20e65 100644 Binary files a/mp5/img_my-1.png and b/mp5/img_my-1.png differ diff --git a/mp5/img_my.tex b/mp5/img_my.tex index bbafa21..b2ecb1f 100644 --- a/mp5/img_my.tex +++ b/mp5/img_my.tex @@ -3,12 +3,12 @@ \begin{tikzpicture} \begin{axis}[% -width=2.604in, -height=2.604in, -at={(0.962in,0.66in)}, +width=1.736in, +height=1.736in, +at={(0.75in,0.653in)}, scale only axis, -point meta min=-0.0128979816802523, -point meta max=0.983438722992887, +point meta min=-0.0235938830592792, +point meta max=0.99393991750956, axis on top, xmin=0.5, xmax=250.5, diff --git a/mp5/img_orig-1.png b/mp5/img_orig-1.png index b3099a1..b064be2 100644 Binary files a/mp5/img_orig-1.png and b/mp5/img_orig-1.png differ diff --git a/mp5/img_orig.tex b/mp5/img_orig.tex index 092d4e9..162fa91 100644 --- a/mp5/img_orig.tex +++ b/mp5/img_orig.tex @@ -3,9 +3,9 @@ \begin{tikzpicture} \begin{axis}[% -width=2.604in, -height=2.604in, -at={(0.962in,0.66in)}, +width=1.736in, +height=1.736in, +at={(0.75in,0.653in)}, scale only axis, point meta min=0.0282583971491394, point meta max=0.921555841989536, diff --git a/mp5/img_rcg-1.png b/mp5/img_rcg-1.png index fd7cf97..48c4fe0 100644 Binary files a/mp5/img_rcg-1.png and b/mp5/img_rcg-1.png differ diff --git a/mp5/img_rcg.tex b/mp5/img_rcg.tex index 85b5ede..2844301 100644 --- a/mp5/img_rcg.tex +++ b/mp5/img_rcg.tex @@ -3,12 +3,12 @@ \begin{tikzpicture} \begin{axis}[% -width=2.604in, -height=2.604in, -at={(0.962in,0.66in)}, +width=1.736in, +height=1.736in, +at={(0.75in,0.653in)}, scale only axis, -point meta min=-0.0235938830592846, -point meta max=0.993939917509565, +point meta min=0.0282583971491394, +point meta max=0.921555841989536, axis on top, xmin=0.5, xmax=250.5, diff --git a/mp5/res_log.tex b/mp5/res_log.tex index 5560c34..dc2edef 100644 --- a/mp5/res_log.tex +++ b/mp5/res_log.tex @@ -6,14 +6,14 @@ \begin{tikzpicture} \begin{axis}[% -width=4.521in, -height=3.566in, -at={(0.758in,0.481in)}, +width=6.028in, +height=4.754in, +at={(1.011in,0.642in)}, scale only axis, xmin=0, -xmax=160, +xmax=50, ymode=log, -ymin=1e-10, +ymin=1e-07, ymax=1, yminorticks=true, axis background/.style={fill=white}, @@ -24,40 +24,40 @@ title={Residual norms over iteration (y is log)} table[row sep=crcr]{% 1 1\\ 2 0.557596535615506\\ -3 0.0776565625508994\\ +3 0.0776565625508993\\ 4 0.0198777323861488\\ -5 0.0079699888022587\\ -6 0.00379999756962288\\ -7 0.00203749487265271\\ +5 0.00796998880225869\\ +6 0.00379999756962287\\ +7 0.0020374948726527\\ 8 0.00117378505868276\\ -9 0.000679072640424651\\ -10 0.000460205525227465\\ +9 0.000679072640424649\\ +10 0.000460205525227464\\ 11 0.000299176988582771\\ 12 0.000208705837325249\\ -13 0.000154155368421639\\ +13 0.000154155368421638\\ 14 0.000112123271112138\\ -15 8.51723029158507e-05\\ -16 6.84145894011082e-05\\ -17 5.22773173463894e-05\\ -18 4.19658990284637e-05\\ +15 8.51723029158506e-05\\ +16 6.84145894011081e-05\\ +17 5.22773173463893e-05\\ +18 4.19658990284636e-05\\ 19 3.35813556680048e-05\\ -20 2.69909819855067e-05\\ +20 2.69909819855066e-05\\ 21 2.16953761012216e-05\\ 22 1.75366202909715e-05\\ 23 1.58613744370523e-05\\ 24 1.07527796769547e-05\\ 25 1.21386374874815e-05\\ -26 1.0281869987924e-05\\ -27 8.94827138078528e-06\\ -28 7.32098660262364e-06\\ -29 6.29855369167728e-06\\ -30 5.75608316894849e-06\\ -31 5.01303204699424e-06\\ -32 4.32711144148809e-06\\ -33 3.75161010629662e-06\\ -34 3.13429056757288e-06\\ -35 2.97535388105767e-06\\ -36 2.59579082920429e-06\\ +26 1.02818699879239e-05\\ +27 8.94827138078525e-06\\ +28 7.32098660262362e-06\\ +29 6.29855369167726e-06\\ +30 5.75608316894847e-06\\ +31 5.01303204699423e-06\\ +32 4.32711144148808e-06\\ +33 3.75161010629661e-06\\ +34 3.13429056757287e-06\\ +35 2.97535388105766e-06\\ +36 2.59579082920428e-06\\ 37 2.35613630297938e-06\\ 38 2.13570046200869e-06\\ 39 1.91918226507556e-06\\ @@ -65,115 +65,9 @@ title={Residual norms over iteration (y is log)} 41 1.60497187780807e-06\\ 42 1.50673230165654e-06\\ 43 1.29912483256279e-06\\ -44 1.18346887626956e-06\\ +44 1.18346887626955e-06\\ 45 1.20647020748118e-06\\ -46 9.32512402536184e-07\\ -47 1.04433975171041e-06\\ -48 7.81977076368343e-07\\ -49 7.06367946061841e-07\\ -50 6.44485405918065e-07\\ -51 5.85991971721864e-07\\ -52 5.19890971305921e-07\\ -53 4.77565688325085e-07\\ -54 4.45837257417216e-07\\ -55 4.52354751810169e-07\\ -56 4.29038013881607e-07\\ -57 4.1992973890364e-07\\ -58 3.83172910236925e-07\\ -59 3.69121286102558e-07\\ -60 3.71629459514197e-07\\ -61 3.46046785121528e-07\\ -62 3.27576103337777e-07\\ -63 3.15320978192872e-07\\ -64 2.96758711344721e-07\\ -65 2.96817636331728e-07\\ -66 2.71124713000926e-07\\ -67 2.6290901313501e-07\\ -68 2.43462036182129e-07\\ -69 2.28404291071362e-07\\ -70 2.24415864473542e-07\\ -71 2.28468445317066e-07\\ -72 2.16184931431008e-07\\ -73 2.03658004162589e-07\\ -74 1.83416377348944e-07\\ -75 1.77025922497327e-07\\ -76 1.70006600401104e-07\\ -77 1.63491825605372e-07\\ -78 1.57088823572822e-07\\ -79 1.62321574880195e-07\\ -80 1.55517018193352e-07\\ -81 1.44132341985947e-07\\ -82 1.33984748126281e-07\\ -83 1.2519682821657e-07\\ -84 1.21215390780982e-07\\ -85 1.15338855777103e-07\\ -86 1.08276150400166e-07\\ -87 1.0480512415693e-07\\ -88 1.01804326380995e-07\\ -89 1.00101662634653e-07\\ -90 9.48101967192299e-08\\ -91 8.8924065689681e-08\\ -92 8.8198911570793e-08\\ -93 8.26647202805877e-08\\ -94 7.78552030683553e-08\\ -95 8.16807953528378e-08\\ -96 7.66807903210005e-08\\ -97 7.25436978662762e-08\\ -98 6.71702595720641e-08\\ -99 7.01343166575373e-08\\ -100 6.80449977565033e-08\\ -101 6.68192875014314e-08\\ -102 6.22828481503882e-08\\ -103 6.14945471895139e-08\\ -104 6.70743224722515e-08\\ -105 6.88753801346864e-08\\ -106 6.74234915968034e-08\\ -107 6.3875299735169e-08\\ -108 6.10832293660889e-08\\ -109 5.60972305769167e-08\\ -110 5.08646226784856e-08\\ -111 4.9561687694454e-08\\ -112 4.46580704300798e-08\\ -113 4.26878173046204e-08\\ -114 4.10291136047614e-08\\ -115 3.78768817391897e-08\\ -116 3.73532345146491e-08\\ -117 3.51670172399507e-08\\ -118 3.22365221922065e-08\\ -119 3.09141086362976e-08\\ -120 3.02505083958211e-08\\ -121 2.87114562212435e-08\\ -122 2.66853094500274e-08\\ -123 2.6004937830953e-08\\ -124 2.5128996812777e-08\\ -125 2.3900587385536e-08\\ -126 2.2409516154494e-08\\ -127 2.01607767874174e-08\\ -128 1.92165407176116e-08\\ -129 1.82690090540455e-08\\ -130 1.78770817200396e-08\\ -131 1.90428945268579e-08\\ -132 1.79884322125703e-08\\ -133 1.63052075399289e-08\\ -134 1.64180505448727e-08\\ -135 1.53303006209212e-08\\ -136 1.4871760637339e-08\\ -137 1.49330577072074e-08\\ -138 1.41966980752516e-08\\ -139 1.34094869141848e-08\\ -140 1.38131070735712e-08\\ -141 1.32790829181307e-08\\ -142 1.29281208590769e-08\\ -143 1.15621456920523e-08\\ -144 1.12246784883697e-08\\ -145 1.09924839400482e-08\\ -146 1.05286801140992e-08\\ -147 9.87772386372883e-09\\ -148 9.8725860305187e-09\\ -149 9.86619410929918e-09\\ -150 9.8729284798242e-09\\ -151 8.57478280643735e-09\\ -152 7.71779322745324e-09\\ +46 9.3251240253618e-07\\ }; \addplot [color=mycolor2, forget plot] table[row sep=crcr]{% @@ -185,24 +79,24 @@ title={Residual norms over iteration (y is log)} 6 6.2599388664747e-05\\ 7 3.67776811885644e-05\\ 8 2.26985377046381e-05\\ -9 2.75130507463433e-05\\ -10 1.74951186586757e-05\\ +9 2.75130507463434e-05\\ +10 1.74951186586756e-05\\ 11 2.49605697423791e-05\\ 12 1.12366572676273e-05\\ 13 1.54813768580115e-05\\ 14 1.23158281548519e-05\\ -15 8.3580459050464e-06\\ +15 8.35804590504644e-06\\ 16 1.06813390449761e-05\\ -17 4.65224806020401e-06\\ -18 4.34451840639607e-06\\ -19 1.9597444994322e-06\\ -20 1.88311897094725e-06\\ -21 1.76128803348424e-06\\ -22 1.27524022549895e-06\\ -23 1.36310372428712e-06\\ -24 1.03510657531695e-06\\ -25 1.00121067351792e-06\\ -26 9.55653227050214e-07\\ +17 4.65224806020403e-06\\ +18 4.34451840639611e-06\\ +19 1.95974449943222e-06\\ +20 1.88311897094728e-06\\ +21 1.76128803348428e-06\\ +22 1.275240225499e-06\\ +23 1.36310372428718e-06\\ +24 1.03510657531701e-06\\ +25 1.00121067351798e-06\\ +26 9.55653227048963e-07\\ }; \end{axis} \end{tikzpicture}% \ No newline at end of file