%--------------------------- example_1 -----------------------------------%
%
% This script runs Alg. 5 (LSR1_SC) from the manuscript using default
% parameters (different parameter values can affect the outcomes of the
% algorithm)
%
% SC-SR1: MATLAB Software for Limited-Memory SR1 Trust-Region Methods,
% (Brust,Burdakov,Erway,Marcia,2018-2022)                               [1]
%
% The algorithm can be used for general unconstrained minimization problems
%
%                           minimize f(x),
%
% where f:R^n -> R. In this example the objective function is the
% Rosenbrock objective and n = 10000
%
% To run this script type:
%
% > example_1
%
%-------------------------------------------------------------------------%
% 04/27/21, J.B, Preparation for release

clc;
clear;

addpath(genpath('../ALGS'));
addpath(genpath('../EXTERNAL'));
addpath(genpath('../AUXILIARY'));

% Rosenbrock objective function and gradient
% Inputs to LSR1_SC
func = @(x)( rosen_obj(x) );
grad = @(x)( rosen_grad(x) );

% Problem dimension
n = 10000;

% This example uses default parameters, which are described in
% the comments of LSR1_SC.m. Only exceptions are to print the outputs,
% use an identity initialization
pars.print       = 1;
pars.whichInit   = 1;

% Initial guess (solution is xsol=ones(n,1), f(xsol)=0)
x0 = zeros(n,1);
x0(1) = 30;

% Example
fprintf('Example 1 ##########################################\n');    
fprintf('Rosenbrock objective: f(x)                         \n');
fprintf('                      n = %i                       \n',n);
fprintf('                     f0 = %0.5g                    \n',func(x0));
fprintf('               norm(g0) = %0.5g                    \n',norm(grad(x0)));
fprintf('\n');
fprintf('Algorithm: SC_SR1                                   \n');
fprintf('####################################################\n');
fprintf('\n');
% Call to the optimization algorithm
[xk1,gk1,fk1,out1] = LSR1_SC(x0,func,grad,pars);
