% Define fixed gamma value
fixed_gamma = 0.5;

% Define a and b as functions of gamma
a = @(gamma) (1 - sqrt(gamma))^2;
b = @(gamma) (1 + sqrt(gamma))^2;

% Define Marchenko-Pastur PDF using arrayfun for element-wise evaluation
mp_pdf = @(s, gamma) arrayfun(@(x) (1 / (2 * pi * gamma * x)) * sqrt((b(gamma) - x) * (x - a(gamma))) * (x >= a(gamma) & x <= b(gamma)), s);

% Define w(t), v(t), and u(t) functions
w_t = @(t, gamma) (1 - gamma * integral(@(s) (1 - exp(-t * s)) .* mp_pdf(s, gamma), a(gamma), b(gamma)))^2;
v_t = @(t, gamma) integral(@(s) exp(-2 * t * s) .* mp_pdf(s, gamma), a(gamma), b(gamma));
u_t = @(t, gamma) integral(@(s) s .* exp(-2 * t * s) .* mp_pdf(s, gamma), a(gamma), b(gamma));

% Define range for t
t_values = linspace(0, 100, 1000);

% Compute values for w(t) * v(t) and u(t) for the fixed gamma value
w_times_v_values = arrayfun(@(t) w_t(t, fixed_gamma) * v_t(t, fixed_gamma), t_values);
u_values = arrayfun(@(t) u_t(t, fixed_gamma), t_values);

% Compute values for w(t) * v(t) and u(t) for the fixed gamma value
v_values = arrayfun(@(t) v_t(t, fixed_gamma), t_values);
u_dividedby_w_values = arrayfun(@(t) u_t(t, fixed_gamma) / w_t(t, fixed_gamma) , t_values);

font_size_legend = 14;
font_size_axis = 16;

% Plot w(t) * v(t) and u(t) for the fixed gamma value
loglog(t_values, w_times_v_values, t_values, u_values, ...
    'LineWidth', 2);
% ytick_labels = {'0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1'};
xlabel('$T$', 'Interpreter', 'latex', 'FontSize', font_size_axis);
ylabel('Function value', 'Interpreter', 'latex', 'FontSize', font_size_axis);
legend('LHS (signal component)', 'RHS (signal component)');
title('Underparameterized ($\zeta_{\ast} = 0.5$)', 'Interpreter', 'latex', 'FontSize', font_size_axis);
grid on;
legend box off
legend('Location', 'northeast', 'FontSize', font_size_legend)

saveas(gcf, 'gf_limit_mismatch_in_t_underparam_bias_actual', 'epsc')
saveas(gcf, 'gf_limit_mismatch_in_t_underparam_bias_actual', 'png')


