compute_obj = -(sqrt(1 - k) * (t_k(k)^6 * (2 * m * (3 * m + 2) + 4) - t_k(k)^5 * (m * (m * (5 * m + 6) + 11) + 12) + m^6 + 2 * t_k(k)^7 - t_k(k)^8 - t_k(k)^4 * (m * (3 * m * (m * (3 * m + 2) - 3) - 16) - 9) - 2 * m^3 * t_k(k)^2 * (3 * m^3 + 2 * m + 3) + m^2 * t_k(k)^3 * (m * (3 * m * (5 * m + 4) + 1) - 4)) + sqrt(k) * (t_k(k)^4 * (m * (9 * m * (m * (m + 4) + 5) + 28) + 9) - m^4 * (3 * m - 2) - t_k(k)^6 * (6 * m * (m + 2) + 10) + t_k(k)^5 * (4 * m^3 + 12 * m + 8) + t_k(k)^8 + m * t_k(k)^2 * (m * (m * (4 * m^3 + 3 * m + 9) + 6) - 8) + 2 * m^2 * t_k(k) * (3 * m - 2) - 2 * m * t_k(k)^3 * (m * (m * (6 * m * (m + 2) + 7) + 6) - 2))) / (18 * t_k(k)^3 * (2 * t_k(k) - (m - t_k(k))^2));
define_t = (sqrt(k) * ((m / t + 2) / 3) - sqrt(1 - k) * ((1 / 3) * (2 + (m / t) + ((2 * m + t) / ((m - t)^2 - 2 * t))))) / (sqrt(k) * (2 * m^3 - 3 * (1 + m)^2 * t + t^3) / (3 * ((m - t)^2 - 2 * t)) - sqrt(1 - k) * ((2 * m + t) / 3));
m_values = linspace(0, 1, 100);
k_solutions = zeros(size(m_values));
t_solutions = zeros(size(m_values));
for i = 1:length(m_values)
objective_with_t = compute_obj;
d_obj_d_k = diff(objective_with_t, k);
d_obj_d_k_fn = matlabFunction(d_obj_d_k, 'Vars', [k, t]);
opt_k_fn = @(k_val) d_obj_d_k_fn(k_val, t_k(k_val));
options = optimset('Display', 'off');
k_opt = fminbnd(@(k) abs(opt_k_fn(k)), 0.5, 1, options);
func = matlabFunction(t_k(k) - define_t, 'Vars', t);
t_opt = fzero(func, 0.7);
disp(table(m_values', k_solutions', t_solutions', 'VariableNames', {'m', 'k_opt', 't_opt'}));
plot(m_values, k_solutions, 'b-', 'LineWidth', 1.5);
plot(m_values, t_solutions, 'r--', 'LineWidth', 1.5);
legend('Optimal k', 'Optimal t');
title('Stackelberg Equilibrium Solutions');