function score = validate3(whichstart, x) % VALIDATE3 : Validate output from Homework 3 % % score = validate3(whichstart, x); % % Check the one- and two-norms of a solution vector "x" % to the linear system in CS 240A Homework 3. Return: % 1: success, correct answer % 0: failure, wrong answer % -1: unknown, don't have a validation for this problem size. % % John R. Gilbert 12 Feb 2006 % whichstart = 0: A = identity matrix, b = (1:n)' % whichstart = 1: A = 3D model problem, b = (1:n)' n = length(x); if whichstart == 0 score = norm(x - (1:n)') < 1e-3/norm((1:n)'); return; end; if whichstart == 1 % values of n for which we can validate with whichstart=1 sizes = [ 1 8 27 64 125 216 343 512 729 1000 1331 1728 2197 2744 3375 4096 4913 5832 6859 8000]; norm1 = 1.0e8 * [0.00000000166667 0.00000012000000 0.00000203960784 0.00001632982456 0.00008427151515 0.00032690763847 0.00103809093064 0.00284236743332 0.00694260026760 0.01548630388510 0.03208372492816 0.06251477176100 0.11566596067841 0.20474261275177 0.34880560123076 0.57468601538073 0.91933517259960 1.43267147662368 2.18098968559791 3.25100221975350]; norm2 = 1.0e+6 * [0.00000016666667 0.00000443621460 0.00004180345581 0.00022091898732 0.00082777417437 0.00247448998919 0.00630606378618 0.01427117250277 0.02946259283900 0.05653238399832 0.10218664488534 0.17576438168196 0.28990478851359 0.46130704344037 0.71158654724393 1.06823137835436 1.56566260000087 2.24640193240096 3.16235019129708 4.37617979264501]; i = find(sizes == n); if isempty(i) fprintf('Sorry, no validation available for n=%d\n',n); score = -1; return; end; check1 = abs((norm(x,1)-norm1(i))/norm1(i)); check2 = abs((norm(x,2)-norm2(i))/norm2(i)); score = (check1 < 1e-3) && (check2 < 1e-3); return; end; fprintf('Sorry, no validation available for whichstart=%d\n',whichstart); return;