
function [solution, alfa, beta, f_est, f_eng] = build_problem(model)


    Kx = build_kernel_matrix(model.vectors_est);
    Ky = build_kernel_matrix(model.vectors_eng);


%     num_lines = rows(Ky);
%    
%
%     B1 = horzcat(zeros(num_lines, num_lines), Ky * Kx);
%     B2 = horzcat(Kx * Ky, zeros(num_lines, num_lines));
%     B = vertcat(B1, B2);
%     
%     
%     k = 0; % 0.001;                      % page3 left bottom: D may be singular due to centering and needs to be regularized
%     
%     Dlu = Kx + eye(num_lines) * k;  % page3 left bottom: D may be singular due to centering and needs to be regularized
%     Dbr = Ky + eye(num_lines) * k;
%     D1 = horzcat(Dlu * Dlu, zeros(num_lines, num_lines));
%     D2 = horzcat(zeros(num_lines, num_lines), Dbr * Dbr);
%     D = vertcat(D1, D2);
% 
%     
%     C = chol(D);
%     
%     
%     
%     
%     
%     
%     % solution = eigs(B, D);            % may return less lines than we need
%     
%     sigma = 0;
%     
%     solution = eigs(B, D, num_lines * 2, sigma);
%     
%     opts = struct;
%     opts.li = 0;
%     opts.isreal = 1;
%     opts.issym = 1;
%     
%     solution = eigs(B, D, num_lines * 2, sigma, opts);   %  return the k largest magnitude eigenvalues
%     
%     sol_rows = rows(solution);
%     alfa = solution(1 : sol_rows/2, :);
%     beta = solution(1 : sol_rows/2, :);
    
    
    solution = [];
    [alfa, beta] = canoncorr(Kx, Ky);

    
    f_est = model.vectors_est * alfa;     % same as sum_i alfa_i * x_i;
    f_eng = model.vectors_eng * beta;
    
    
%     maxi = rows(alfa);
%     maxcols = cols(alfa);
%     arows = rows(model.vectors_est);
%     brows = rows(model.vectors_eng);
%   
%     % f_est = zeros(maxi, maxi);
%     % f_eng = zeros(maxi, maxi);
%     
%     f_est = zeros(arows, maxcols);
%     f_eng = zeros(brows, maxcols);
%     
%     for i = 1:maxi
%         
%         f_est = f_est + model.vectors_est(:, i) * alfa(i, :);
%         f_eng = f_eng + model.vectors_eng(:, i) * beta(i, :);
%         
%     end   
    
    
    

end
