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: performTrilateration.m
    path of file: ./repos/positioning-algorithms-for-uwb-matlab/helper_functions
    
    the code of the file until where you have to start completion: function [X, Y, Z] = performTrilateration(mat_Anc, vec_Ranges)

    
function [X, Y, Z] = performTrilateration(mat_Anc, vec_Ranges)

% Extract the given reference anchors
% A1 = mat_Anc(1,:);
% A2 = mat_Anc(2,:);
% A3 = mat_Anc(3,:);
% A4 = mat_Anc(4,:);

% Extract the measured ranges (distanct values)
d_1 = vec_Ranges(1);
d_2 = vec_Ranges(2);
d_3 = vec_Ranges(3);
d_4 = vec_Ranges(4);  % the fourth range is used only in 3D

% Extract parameters required for Trilateration algorithm
U = mat_Anc(2, 1);     % the X-axis value of Anchor A2
V_x = mat_Anc(3, 1);
V_y = mat_Anc(3, 2);
% U = A2(1);     % the X-axis value of Anchor A2
% V_x = A3(1);
% V_y = A3(2);

X = (d_1^2 - d_2^2 + U^2)./ (2 .* U);

Y = (d_1^2 - d_3^2 + V_x^2 + V_y^2 - 2.* X .* V_x)./(2 .* V_y);

% Note: in fact, square root has +/- value. we assume only positive value here in 3D.
Z = sqrt(d_1^2 - X^2 - Y^2);  




%%% The following is for an arbitary anchors set-up, which is currently 
%%% not necessary for the implementation purposes of this project
%{
% Constant Declaration for Geometric precision of Dilution
MAXZERO = 0.001;

len = length(r1);             % Length of the ranging vectors 
 
% Error Checking for Anchors Positions 
ancPos = norm(P2 - P1);
if(ancPos <= MAXZERO)
    % Error occured 
    msg = 'Error: Anchors P1 & P2 are concentric, Not good for positioning!';
    error(msg);
end