function LQR_rail_Rosenbrock(k)
% Computes the optimal feedback via the low-rank Rosenbrock[1,2] methods for
% the selective cooling of Steel profiles application described in [3,4,5].
%
% Usage: LQR_Rail(k,shifts,inexact,Galerkin,istest)
%
% Inputs:
%
% k           k-stage Rosenbrock method
%             possible values: 1, 2
%             (optinal, defaults to 2)
%
% References:
%
% [1] N. Lang, H. Mena, J. Saak, On the benefits of the LDLT factorization
%     for largescale differential matrix equation solvers, Linear Algebra
%     Appl. 480 (2015) 44–71.  https://doi.org/10.1016/j.laa.2015.04.006.
%
% [2] N. Lang, Numerical methods for large-scale linear time-varying
%     control systems and related differential matrix equations,
%     Dissertation, Technische Universität Chemnitz, Chemnitz, Germany,
%     logos-Verlag, Berlin, ISBN 978-3-8325-4700-4 (Jun. 2017).
%     URL https://www.logos-verlag.de/cgi-bin/buch/isbn/4700
%
% [3] J. Saak, Effiziente numerische Lösung eines
%     Optimalsteuerungsproblems für die Abkühlung von Stahlprofilen,
%     Diplomarbeit, Fachbereich 3/Mathematik und Informatik, Universität
%     Bremen, D-28334 Bremen (Sep. 2003).
%
% [4] P. Benner, J. Saak, A semi-discretized heat transfer model for
%     optimal cooling of steel profiles, in: P. Benner, V. Mehrmann, D.
%     Sorensen (Eds.), Dimension Reduction of Large-Scale Systems, Vol. 45
%     of Lect. Notes Comput. Sci. Eng., Springer-Verlag, Berlin/Heidelberg,
%     Germany, 2005, pp. 353–356. https://doi.org/10.1007/3-540-27909-1_19.
%
% [5] J. Saak, Efficient numerical solution of large scale algebraic matrix
%     equations in PDE control and model order reduction, Dissertation,
%     Technische Universität Chemnitz, Chemnitz, Germany (Jul. 2009).
%     URL http://nbn-resolving.de/urn:nbn:de:bsz:ch1-200901642
%

%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, see <http://www.gnu.org/licenses/>.
%
% Copyright (C) Jens Saak, Martin Koehler, Peter Benner and others
%               2009-2020
%
narginchk(0,1);
if nargin<1, k=2; end

set operation

oper = operatormanager('default');

% Problem data
eqn = getrail(0);
opts.norm = 'fro';
% ADI tolerances and maximum iteration number
opts.adi.maxiter = 100;
opts.adi.res_tol = 1e-14;
opts.adi.rel_diff_tol = 1e-16;
opts.adi.info = 0;
opts.adi.compute_sol_fac = 1;
opts.adi.accumulateK = 1;

eqn.type = 'T';
%Heuristic shift parameters via projection
opts.shifts.num_desired=7;
opts.shifts.method = 'projection';

Rosenbrock parameters

opts.rosenbrock.time_steps = 0 : 50 : 4500;
opts.rosenbrock.stage = k;
opts.rosenbrock.info = 1;
opts.rosenbrock.gamma = 1 + 1 / sqrt(2);
opts.rosenbrock.save_solution = 0;
tic;
[out_ros]=mess_rosenbrock_dre(eqn,opts,oper);
toc;
y = zeros(1,length(out_ros.Ks));
for i=1:length(out_ros.Ks)
    y(i) = out_ros.Ks{i}(1,77);
end
x = opts.rosenbrock.time_steps;
figure(1);
plot(x,y);
title('evolution of component (1,77) of the optimal feedback');
xlabel('time');
ylabel('magnitude');
Warning: Initial condition factor L0 is not defined or corrupted. Setting it to
the zero vector. 
Warning: Initial condition factor D0 is not defined or corrupted. Setting it to
the identity matrix. 
Rosenbrock step 4450 s
Rosenbrock step 4400 s
Rosenbrock step 4350 s
Rosenbrock step 4300 s
Rosenbrock step 4250 s
Rosenbrock step 4200 s
Rosenbrock step 4150 s
Rosenbrock step 4100 s
Rosenbrock step 4050 s
Rosenbrock step 4000 s
Rosenbrock step 3950 s
Rosenbrock step 3900 s
Rosenbrock step 3850 s
Rosenbrock step 3800 s
Rosenbrock step 3750 s
Rosenbrock step 3700 s
Rosenbrock step 3650 s
Rosenbrock step 3600 s
Rosenbrock step 3550 s
Rosenbrock step 3500 s
Rosenbrock step 3450 s
Rosenbrock step 3400 s
Rosenbrock step 3350 s
Rosenbrock step 3300 s
Rosenbrock step 3250 s
Rosenbrock step 3200 s
Rosenbrock step 3150 s
Rosenbrock step 3100 s
Rosenbrock step 3050 s
Rosenbrock step 3000 s
Rosenbrock step 2950 s
Rosenbrock step 2900 s
Rosenbrock step 2850 s
Rosenbrock step 2800 s
Rosenbrock step 2750 s
Rosenbrock step 2700 s
Rosenbrock step 2650 s
Rosenbrock step 2600 s
Rosenbrock step 2550 s
Rosenbrock step 2500 s
Rosenbrock step 2450 s
Rosenbrock step 2400 s
Rosenbrock step 2350 s
Rosenbrock step 2300 s
Rosenbrock step 2250 s
Rosenbrock step 2200 s
Rosenbrock step 2150 s
Rosenbrock step 2100 s
Rosenbrock step 2050 s
Rosenbrock step 2000 s
Rosenbrock step 1950 s
Rosenbrock step 1900 s
Rosenbrock step 1850 s
Rosenbrock step 1800 s
Rosenbrock step 1750 s
Rosenbrock step 1700 s
Rosenbrock step 1650 s
Rosenbrock step 1600 s
Rosenbrock step 1550 s
Rosenbrock step 1500 s
Rosenbrock step 1450 s
Rosenbrock step 1400 s
Rosenbrock step 1350 s
Rosenbrock step 1300 s
Rosenbrock step 1250 s
Rosenbrock step 1200 s
Rosenbrock step 1150 s
Rosenbrock step 1100 s
Rosenbrock step 1050 s
Rosenbrock step 1000 s
Rosenbrock step  950 s
Rosenbrock step  900 s
Rosenbrock step  850 s
Rosenbrock step  800 s
Rosenbrock step  750 s
Rosenbrock step  700 s
Rosenbrock step  650 s
Rosenbrock step  600 s
Rosenbrock step  550 s
Rosenbrock step  500 s
Rosenbrock step  450 s
Rosenbrock step  400 s
Rosenbrock step  350 s
Rosenbrock step  300 s
Rosenbrock step  250 s
Rosenbrock step  200 s
Rosenbrock step  150 s
Rosenbrock step  100 s
Rosenbrock step   50 s
Rosenbrock step    0 s
Elapsed time is 81.204866 seconds.