function xnew = restrict(x,m1,m2)
% This function computes the restriction of an (m1)st level network
% of resistors to an (m2)nd level such network, where a network at
% the mth level is the stacking of three (m-1)st level networks, and
% a 1st level network is a Y shaped network. For example, if
% m1 = 2 and m2 = 1, then given edges like this:
%
%       |
%      / \
%     |   |
%    / \ / \
%
% and given resistances on each, we calculate resistances for the equivalent
% network on just the three outer nodes that looks like:
%
%     |
%    / \
% 
% support files: restrictall.m
%
% INPUT: the resistances are assumed to be in a 3^m1 by 3 matrix,
% which is made of the matrices for the top, bottom left, and bottom right
% (m-1)st level networks respectively, and a 1st level network's
% matrix (for a Y circuit) lists the top, bottom left, and bottom
% right circuits' resistances across a single row.

% OUTPUT: a matrix of the same type inputed, but for an (m2)nd level
% network (a 3^m2 by 3 matrix).

xnew = restrictall(x(1:3^(m1-m2),:),m1-m2) ;

for k = 2:3^m2
  xnew = [xnew ; restrictall(x((k-1)*3^(m1-m2)+1:k*3^(m1-m2),:),m1-m2)] ;
end