%This function determines the condition number for the specified number of GPS
%satellites. The condition number is the worst possible error magnification 
%factor for the specified number of GPS satellites. The EMF measures how much 
%the error of the approximate location of a person using GPS will increase due 
%to inaccuracies of their GPS reciever's clock.

%This function requires the other functions:
    %SatelliteEMF
    %MVNewtonsInputs
    %FCreator
    %DCreator
    
%The input to this function is the number of GPS satellites.

function Result=SatelliteConditionNumber(NumberOfSatellites)

%The following loop finds the error magnification factor and forward error for 
%100 different configurations of the specified number of GPS satellites.
%The Forward Error and EMF are stored in a matrix in that order.
ErrorStats=[];
for i=1:100
    ErrorStats=[ErrorStats;SatelliteEMF(NumberOfSatellites)];
end

%The following lines find the largest and median EMF and error.
%The condition number is the largest EMF.
[Maxes,Indices]=max(ErrorStats);
ConditionNumber=Maxes(2);
BiggestError=Maxes(1);
Medians=median(ErrorStats);
MedianEMF=Medians(2);
MedianError=Medians(1);

%The function outputs a vector with the Condition Number, the biggest forward 
%error, the median EMF, and the median forward error in that order.
Result=[ConditionNumber,BiggestError,MedianEMF,MedianError];