Cody

# Problem 498. Find the Kronecker Tensor Product without using KRON

Solution 458700

Submitted on 19 Jun 2014 by rifat
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
% test for 'KRON' usage fid = fopen(which('mykron'),'r'); c=onCleanup(@()fclose(fid)); tline=fgetl(fid); while ischar(tline) if (strfind(tline,'=kron')>0), error('Don''t use kron'); end if (strfind(tline,' kron')>0), error('Don''t use kron'); end if (strfind(tline,'+kron')>0)|(strfind(tline,'*kron')>0), error('Don''t use kron'); end if (strfind(tline,'-kron')>0), error('Don''t use kron'); end tline = fgetl(fid) end;

tline = '' tline = a=repmat(y,size(x)) tline = z=num2cell(x); tline = for i=1:numel(z) tline = z{i}=z{i}*ones(size(y)); tline = end tline = b=cell2mat(z); tline = '' tline = a.*b; tline = '' tline = %This code written by profile_id 3437206 tline = -1

2   Pass
%% test 1 x =1:3; y =2:4; y_correct = [2 3 4 4 6 8 6 9 12]; assert(isequal(mykron(x,y),y_correct))

a = 2 3 4 2 3 4 2 3 4

3   Pass
%% test 2 x = randi(10,3,3); y = 2:4; z_correct = kron(x,y); assert(isequal(mykron(x,y),z_correct))

a = 2 3 4 2 3 4 2 3 4 2 3 4 2 3 4 2 3 4 2 3 4 2 3 4 2 3 4