You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: cart2geo.m
    path of file: ./repos/nav_matlab/example/gps_spp_test/easysuite
    
    the code of the file until where you have to start completion: function [phi_res,lambda_res,h] = cart2geo(X,Y,Z,i)

    
function [phi_res,lambda_res,h] = cart2geo(X,Y,Z,i)
%CART2GEO Conversion of Cartesian coordinates (X,Y,Z) to geographical
%	      coordinates (phi,lambda,h) on a selected reference ellipsoid
%         Choices i of Reference Ellipsoid for Geographical Coordinates
%          	 1. International Ellipsoid 1924
%	         2. International Ellipsoid 1967
%	         3. World Geodetic System 1972
%	         4. Geodetic Reference System 1980
%	         5. World Geodetic System 1984

%Kai Borre 10-13-98
%Copyright (c) by Kai Borre
%$Revision: 1.0 $  $Date: 1998/10/23  $

a = [6378388 6378160 6378135 6378137 6378137];
f = [1/297 1/298.247 1/298.26 1/298.257222101 1/298.257223563];

lambda = atan2(Y,X);
ex2 = (2-f(i))*f(i)/((1-f(i))^2);
c = a(i)*sqrt(1+ex2);
phi = atan(Z/((sqrt(X^2+Y^2)*(1-(2-f(i)))*f(i))));

h = 0.1; oldh = 0;
while abs(h-oldh) > 1.e-13
   oldh = h;
   N = c/sqrt(1+ex2*cos(phi)^2);
   phi = atan(Z/((sqrt(X^2+Y^2)*(1-(2-f(i))*f(i)*N/(N+h)))));
   h = sqrt(X^2+Y^2)/cos(phi)-N;
end