function tensor_test(ndims, len) % tensor_test -- Test of "tensor_mul" and tensor_sol". % tensor_test(ndims, len) exercizes "tensor_mul" and % "tensor_sol" with two random arrays, each with % ndims, where each dimension has length len. % All possible summation directions are tested. % The elapsed time and an error-norm are displayed. % % Also see: tensor_mul, tensor_sol. % Copyright (C) 1998 Dr. Charles R. Denham, ZYDECO. % All Rights Reserved. % Disclosure without explicit written consent from the % copyright owner does not constitute publication. % Version of 18-Sep-1998 08:41:32. help(mfilename) if nargin < 1, ndims = 3; end if nargin < 2, len = 2; end if ischar(ndims), ndims = eval(ndims); end if ischar(len), len = eval(len); end a = rand(ones(1, ndims)*len) - 0.5; u = rand(ones(1, ndims)*len) - 0.5; err = zeros(ndims^2, 1); tic k = 0; for j = 1:ndims disp([' ## Remaining: ' int2str(ndims^2 - k)]); for i = 1:ndims b = tensor_mul(a, u, i, j); x = tensor_sol(a, b, i, j); k = k+1; e = x - u; err(k) = norm(e(:)); end end toc err_norm = norm(err)