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: refractRay.m
    path of file: ./repos/gkaModelEye/model/quadric/relations/+quadric
    
    the code of the file until where you have to start completion: function Rr = refractRay(R,N,nRel)
% Returns a refracted ray given an incident ray, surface normal, and index 
%
% Syntax:
%  Rr = quadric.refractRay(R,N,nRel)
%
% Description:
%   Snell's Law of optical refraction may be expressed in three-dimensions
%   in matrix form. This routine provides the refracted ray after an
%   incident ray encounters a surface with a given surface normal, and
%   possesing a given relative index of refraction. If the ray is found to
%   experience total internal reflection, the routine returns nans for the
%   refracted ray.
%
%   This approach to optical systems is described in:
%
%       Langenbucher, Achim, et al. "Ray tracing through a schematic eye
%       containing second-order (quadric) surfaces using 4x4 matrix
%       notation." Ophthalmic and Physiological Optics 26.2 (2006):
%       180-188.
%
% Inputs:
%   R                     - 3x2 matrix that specifies the incident ray as 
%                           a vector of the form [p; u], corresponding to
%                               R = p + t*u
%                           where p is vector origin, u is the direction
%                           expressed as a unit step, and t is unity for a
%                           unit vector.
%   N                     - 3x2 matrix that specifies the surface normal as 
%                           a vector of the form [p; u], corresponding to
%                               N = p + t*u
%                           where p is vector origin, u is the direction
%                           expressed as a unit step, and t is unity for a
%                           unit vector.
%   nRel                  - The relative index of refraction n / n', where
%                           n is the index of refraction of the medium of
%                           the incident ray, and n' is the index of
%                           refraction of the medium of the surface that
%                           the ray has intersected.
%
% Outputs:
%   Rr                    - 3x2 matrix that specifies the refracted ray as 
%                           a vector of the form [p; u], corresponding to
%                               Rr = p + t*u
%                           where p is vector origin, u is the direction
%                           expressed as a unit step, and t is unity for a

    
function Rr = refractRay(R,N,nRel)
% Returns a refracted ray given an incident ray, surface normal, and index 
%
% Syntax:
%  Rr = quadric.refractRay(R,N,nRel)
%
% Description:
%   Snell's Law of optical refraction may be expressed in three-dimensions
%   in matrix form. This routine provides the refracted ray after an
%   incident ray encounters a surface with a given surface normal, and
%   possesing a given relative index of refraction. If the ray is found to
%   experience total internal reflection, the routine returns nans for the
%   refracted ray.
%
%   This approach to optical systems is described in:
%
%       Langenbucher, Achim, et al. "Ray tracing through a schematic eye
%       containing second-order (quadric) surfaces using 4x4 matrix
%       notation." Ophthalmic and Physiological Optics 26.2 (2006):
%       180-188.
%
% Inputs:
%   R                     - 3x2 matrix that specifies the incident ray as 
%                           a vector of the form [p; u], corresponding to
%                               R = p + t*u
%                           where p is vector origin, u is the direction
%                           expressed as a unit step, and t is unity for a
%                           unit vector.
%   N                     - 3x2 matrix that specifies the surface normal as 
%                           a vector of the form [p; u], corresponding to
%                               N = p + t*u
%                           where p is vector origin, u is the direction
%                           expressed as a unit step, and t is unity for a
%                           unit vector.
%   nRel                  - The relative index of refraction n / n', where
%                           n is the index of refraction of the medium of
%                           the incident ray, and n' is the index of
%                           refraction of the medium of the surface that
%                           the ray has intersected.
%
% Outputs:
%   Rr                    - 3x2 matrix that specifies the refracted ray as 
%                           a vector of the form [p; u], corresponding to
%                               Rr = p + t*u
%                           where p is vector origin, u is the direction
%                           expressed as a unit step, and t is unity for a
%                           unit vector.
%
% Examples:
%{
    % Test 1 from http://www.starkeffects.com/snells-law-vector.shtml
    p=[0;0;0];
    u=[1/sqrt(2);0;1/sqrt(2)];
    R=[p,u];
    n0 = 1;
    n1 = 1.5;
    nRel = n0/n1;
    N=[p,[0;0;-1]];
    Rr = quadric.refractRay(R,N,nRel);
    assert(max(abs(Rr(:,2)-[0.471;0;0.882]))<0.001);
%}
%{
    % Test 2 from http://www.starkeffects.com/snells-law-vector.shtml
    p=[0;0;0];
    u=[4;1;1];
    R = quadric.normalizeRay([p, u]);
    n0 = 1;
    n1 = 1.5;
    nRel = n0/n1;
    u=[0;-2;-1];
    N=quadric.normalizeRay([p,u]);
    Rr = quadric.refractRay(R,N,nRel);
    assert(max(abs(Rr(:,2)-[0.629;0.661;0.409]))<0.001);
%}


% Pre-allocate the output variable
Rr = nan(3,2);

% Clear the nan cases
if any(isnan(R))    
    return
end