function out = S(w)
%function 4.37 on page 239 if Sauer's book in matrix form
%break the input into x,y,z,d
x = w(1);
y = w(2);
z = w(3);
d = w(4);

A1 = 15600; %the four satellite positions
B1 = 7540;  %Everything in kilometers
C1 = 20140;
A2 = 18760;
B2 = 2750;
C2 = 18610;
A3 = 17610;
B3 = 14630;
C3 = 13480;
A4 = 19170;
B4 = 610;
C4 = 18390;

c = 299792.458; %speed of light in kilometers/seconds
%measured time intervals in seconds
t1 = .07074;
t2 = .07220;
t3 = .07690;
t4 = .07242;

r1 = (x-A1)^2 + (y - B1)^2 + (z - C1)^2 - (c*(t1-d))^2;
r2 = (x-A2)^2 + (y - B2)^2 + (z - C2)^2 - (c*(t2-d))^2;
r3 = (x-A3)^2 + (y - B3)^2 + (z - C3)^2 - (c*(t3-d))^2;
r4 = (x-A4)^2 + (y - B4)^2 + (z - C4)^2 - (c*(t4-d))^2;

out = [r1; r2; r3; r4];

