% This function receives inputs in x, y, z, and d and performs one
% iteration of Newton's Multivariate Method
function f = multiNewton(x,y,z,d)

% Below are the constants given in Problem 1
A1 = 15600;
B1 = 7540;
C1 = 20140;
t1 = 0.07074;

A2 = 18760;
B2 = 2750;
C2 = 18610;
t2 = 0.07220;

A3 = 17610;
B3 = 14630;
C3 = 13480;
t3 = 0.07690;

A4 = 19170;
B4 = 610;
C4 = 18390;
t4 = 0.07242;

% c is the speed of light in km/sec
c = 299792.458;

% The initial guess is stored in this vector
x0 = [x; y; z; d];

% These sphere equations describe the positions of the four satellites
F1 = (x - A1)^2 + (y - B1)^2 + (z - C1)^2 - (c * (t1 - d))^2;
F2 = (x - A2)^2 + (y - B2)^2 + (z - C2)^2 - (c * (t2 - d))^2;
F3 = (x - A3)^2 + (y - B3)^2 + (z - C3)^2 - (c * (t3 - d))^2;
F4 = (x - A4)^2 + (y - B4)^2 + (z - C4)^2 - (c * (t4 - d))^2;

% These equations describe the Jacobian, a Matrix of Partial Derivatives
F1x = 2 * (x - A1);
F1y = 2 * (y - B1);
F1z = 2 * (z - C1);
F1d = 2 * c^2 * (t1 - d);

F2x = 2 * (x - A2);
F2y = 2 * (y - B2);
F2z = 2 * (z - C2);
F2d = 2 * c^2 * (t2 - d);

F3x = 2 * (x - A3);
F3y = 2 * (y - B3);
F3z = 2 * (z - C3);
F3d = 2 * c^2 * (t3 - d);

F4x = 2 * (x - A4);
F4y = 2 * (y - B4);
F4z = 2 * (z - C4);
F4d = 2 * c^2 * (t4 - d);

% DF represents the Jacobian Matrix
DF = [F1x F1y F1z F1d; F2x F2y F2z F2d; F3x F3y F3z F3d; F4x F4y F4z F4d];

% The F matrix contains the four sphere equations
F = [F1; F2; F3; F4];

% Now that matrix's have been computed, perform one iteration of Newton's
% Method
s =  DF \ -F;
f = x0 + s;
end
Error using multiNewton (line 30)
Not enough input arguments.