// This file should be loaded with exec filename.sce
// Each column is vector around the circle
function x = circle(n)
x = zeros(2,n);
for i = 1:n,
	j=i-1;
	x(1,i) = cos(j*%pi*2/n);
	x(2,i) = sin(j*%pi*2/n)
end;
endfunction;

// Make each column a unit vector, bomb if one of the vectors is zero
//function x = normalize(y)
//x = y;
//[m, n] = size(y);
//for i = 1:n,
//	nor = norm(y(:,i));
//	x(:,i) = y{:,i)/nor;
//end;
//endfunction;

// Draw arrows from y to x
function x = transA(y)
x = y;
[m, n] = size(y);
scf(0);
clf;
for i = 1:n,
	x(:,i) = A*y(:,i);
end;
minx = min([x(1,:), y(1,:)]);
maxx = max([x(1,:), y(1,:)]);
miny = min([x(2,:), y(2,:)]);
maxy = max([x(2,:), y(2,:)]);
plot([minx, maxx],[miny,maxy],'w.');
for i = 1:n,
	xarrows([y(1,i), x(1,i)], [y(2,i), x(2,i)],-1,5); // 5 =red 1 = size);
end;
plot(y(1,:),y(2,:),'ro');
square(minx, miny, maxx, maxy);
endfunction;

function x = makeUnit(y)
x = y;
[m, n] = size(y);
N = 2;
for i = 1:n,
	N = norm(y(:,i));
	x(:,i) = y(:,i) / N;
end;
endfunction;

function x = randsq(n)
x = 2*(rand(2,n) - 0.5*ones(2,n));
endfunction;


function x = randcir(n)
x = zeros(2,n)
for i = 1:n,
	theta = 2*%pi* rand();
	r = sqrt(rand());
	x(1,i) = r*cos(theta);
	x(2,i) = r*sin(theta);
end;
endfunction;
