% cmpvecs: compare two matrices or vectors (the latter being 1xn matrices).
% Usage: cmpvecs(A, B)

% John Kerl [& Eric Jones :)]
% kerl.john.r@gmail.com
% 2006-05-18

function cmpvecs(A, B)

anr = size(A, 1);
anc = size(A, 2);

bnr = size(B, 1);
bnc = size(B, 2);

if (anr ~= bnr) | (anc ~= bnc)
	error('cmpvecs: Mismatched dimensions %dx%d and %dx%d.', anr, anc, bnr, bnc)
end

abs_err         = abs(A-B);
max_abs_val     = max(max(abs(A)));
rel_err         = abs_err / max_abs_val;
rms_rel_err     = sqrt(sum(sum(rel_err .^2))/ (anr*anc));

max_rel_err     = max(max(rel_err));
max_abs_err     = max(max(abs_err));

fprintf(1, '\n');
fprintf(1, 'Max relative error %11.6e\n', max_rel_err);
fprintf(1, 'RMS relative error %11.6e\n', rms_rel_err);
fprintf(1, 'Max absolute error %11.6e\n', max_abs_err);
fprintf(1, 'Max absolute value %11.6e\n', max_abs_val);
fprintf(1, '\n');
