% Function to estimate the true mach number of a flying aircraft

% Given:
% alt = altitude (m)
% ias = indicated airspeed (knots)

% calculate:
% mtrue = true mach number (dimensionless)

function mtrue = mach(alt,ias)

rho_zero = 1.225;			% density at sea level (kg/m-m-m)
load atmosphere;			% loads ISA atmospheric tables

h = atmosphere(:,1);		% vector with values of altitude
t = atmosphere(:,2);		% vector with values of temperature
r = atmosphere(:,3);		% vector with values of density
a = atmosphere(:,4);		% gvector with values of speed

rho = interp1(h,r,alt,'cubic');	% interpolates to get density of air at any altitude

% calculates the mach number at altitude

mtrue = sqrt(5 * ((rho_zero/rho *((1 + 0.2 * (ias/661.5)^2)...
			^3.5 -1) + 1)^0.286 -1));


