%% Exercise T8, Section 2.3

syms x y z t

%S = [.94 1.2 2.3 1.23;
%  	 0  1.35 2.41 1.08;
%	 2.3 .94 1.2 .74;
%	 2.4 0 1.35 .23]

S = [	1.12 	2.1	1.4	1.06;
	0	1.53	2.3	.56;
	1.4	1.12	2.1	1.16;
	2.3	0	1.53	.75	]

% LHS of equation 1
for i = 1:4;
L{i} = expand( (x-S(i,1))^2 + (y-S(i,2))^2 + (z-S(i,3))^2 );
end

% RHS of equation 1
for i = 1:4;
R{i} = expand( .22 * (t - S(i,4))^2) ;
end

for j = 2:4
	NL{j-1} = L{1} - L{j};
end

for j = 2:4
	NR{j-1} = R{1} - R{j};
end

for i = 1:3;
	
	Temp   = (coeffs(NL{i}-NR{i},x));
	A(i,1) = Temp(2);
	Temp   = (coeffs(NL{i}-NR{i},y));
	A(i,2) = Temp(2);
	Temp   = (coeffs(NL{i}-NR{i},z));
	A(i,3) = Temp(2);
	Temp   = (coeffs(NL{i}-NR{i},t));
	A(i,4) = Temp(2);
	Temp   = double(coeffs(NL{i}-NR{i}));
	A(i,5) = Temp(1);
end

I = double(rref(A))

% Now set x = A(1,end) - A(1,end-1)*s;
% and similarly for y,z and set s = t 
% and plug these into one of the defining quadratics and solve


