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: tr.m
    path of file: ./repos/SGDLibrary/gd_solver
    
    the code of the file until where you have to start completion: function [w, infos]= tr(problem, in_options)
% Trust region medhod algorithm.
%
% Inputs:
%       problem     function (cost/grad/hess)
%       options     options
% Output:
%       w           solution of w
%       infos       information
%
%
%       H_mode:   
%                   "NEWTON"
%                           Hessian HESS of f is used
%                   "QUASI-NEWTON"           
%                           Rank-one updates approximations of the Hessian are
%                           built as in BFGS and the variable HESS is not required.
%
%       subprob_solver:   
%                   "Trustone"
%                   "Cauchy_point"           
%                   "Dogleg"
%
%
% This file is part of GDLibrary and SGDLibrary.
%
% This file was originally created in the book:
%   A. Quarteroni, F. Saleri, P. Gervasio
%   "Scientific Computing with MATLAB and Octave"
%   Springer Science & Business Media, 2014/02/20
%
% Sub-program solvers, dogleg and cauchy point, are originally from the codes 
%   written by Philip D. Loewen.
%   http://www.math.ubc.ca/~loew/m604/mfiles.htm
%
%
%
% TAdjusted by H.Kasai on Apr. 08, 2018
% Modified by H.Kasai on Mar. 23, 2018


    % set dimensions and samples
    d = problem.dim;
    n = problem.samples;     
    
    % set local options 
    local_options = []; 
    local_options.algorithm = 'TR'; 
    local_options.subprob_solver = 'DOGLEG';
    local_options.H_mode = 'QUASI-NEWTON';
    local_options.delta = 0.5;
    local_options.mu = 0.1;    
    local_options.eta1= 0.25;  
    local_options.eta2 = 0.75; 
    local_options.gamma1 = 0.25; 
    local_options.gamma2 = 2;    
    local_options.delta_max = 5;     

    % merge options
    options = mergeOptions(get_default_options(d), local_options);   
    options = mergeOptions(options, in_options);  


    % initialise
    iter = 0;

    
function [w, infos]= tr(problem, in_options)
% Trust region medhod algorithm.
%
% Inputs:
%       problem     function (cost/grad/hess)
%       options     options
% Output:
%       w           solution of w
%       infos       information
%
%
%       H_mode:   
%                   "NEWTON"
%                           Hessian HESS of f is used
%                   "QUASI-NEWTON"           
%                           Rank-one updates approximations of the Hessian are
%                           built as in BFGS and the variable HESS is not required.
%
%       subprob_solver:   
%                   "Trustone"
%                   "Cauchy_point"           
%                   "Dogleg"
%
%
% This file is part of GDLibrary and SGDLibrary.
%
% This file was originally created in the book:
%   A. Quarteroni, F. Saleri, P. Gervasio
%   "Scientific Computing with MATLAB and Octave"
%   Springer Science & Business Media, 2014/02/20
%
% Sub-program solvers, dogleg and cauchy point, are originally from the codes 
%   written by Philip D. Loewen.
%   http://www.math.ubc.ca/~loew/m604/mfiles.htm
%
%
%
% TAdjusted by H.Kasai on Apr. 08, 2018
% Modified by H.Kasai on Mar. 23, 2018


    % set dimensions and samples
    d = problem.dim;
    n = problem.samples;     
    
    % set local options 
    local_options = []; 
    local_options.algorithm = 'TR'; 
    local_options.subprob_solver = 'DOGLEG';
    local_options.H_mode = 'QUASI-NEWTON';
    local_options.delta = 0.5;
    local_options.mu = 0.1;    
    local_options.eta1= 0.25;  
    local_options.eta2 = 0.75; 
    local_options.gamma1 = 0.25; 
    local_options.gamma2 = 2;    
    local_options.delta_max = 5;     

    % merge options
    options = mergeOptions(get_default_options(d), local_options);   
    options = mergeOptions(options, in_options);  


    % initialise
    iter = 0;
    grad_calc_count = 0;
    w = options.w_init;    
    
   % initialize by BB step-size 
    if strcmp(options.step_init_alg, 'bb_init')
        options.step_init = bb_init(problem, w);
    end