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: ukf_update.m
    path of file: ./repos/libDirectional/lib/external/ukfm/ukfm
    
    the code of the file until where you have to start completion: function [up_state, up_P] = ukf_update(state, P, y, h, phi, R, weights)
%UKF_UPDATE Update step of the UKF
%
% Syntax: [up_state, up_P] = ukf_update(state, P, y, h, phi, R, weights)
%
% Inputs:
%    state - state
%    P - covariance matrix

    
function [up_state, up_P] = ukf_update(state, P, y, h, phi, R, weights)
%UKF_UPDATE Update step of the UKF
%
% Syntax: [up_state, up_P] = ukf_update(state, P, y, h, phi, R, weights)
%
% Inputs:
%    state - state
%    P - covariance matrix
%    y - measurement
%    h - measurement function, function
%    phi - retraction, function
%    R -noise covariance matrix
%    weights - weight parameters
%
% Outputs:
%    up_state - updated state
%    up_P - updated covariance matrix

TOL = 1e-9; % tolerance for assuring positivness of P

% set variable size
d = length(P);
l = length(y);

P = P + TOL*eye(d);

% set sigma points
w_u = weights.u;
xis = w_u.sqrt_d_lambda * chol(P)';

% compute measurement sigma_points
ys = zeros(l, 2*d);
y_hat = h(state);
for j = 1:d
    chi_j_plus = phi(state, xis(:, j));
    chi_j_minus = phi(state, -xis(:, j));
    ys(:, j) = h(chi_j_plus);
    ys(:, d + j) = h(chi_j_minus);
end