% Pr(X^(1/3) > Y/2) for two independent uniform variables
% Textbook: Part I, "Two Random Variables", exercise (2022, Midterm)
%
% X, Y ~ U[0,1], independent. The event fails only when X < (Y/2)^3, so
% Pr = 1 - int_0^1 (y/2)^3 dy = 1 - 1/32 = 31/32 = 0.96875.

clearvars; close all
rng(0)

N = 1e6;
X = rand(1, N);
Y = rand(1, N);
event = X.^(1/3) > Y/2;

fprintf('Pr(X^(1/3) > Y/2): theory = %.5f, simulation = %.5f\n', ...
    31/32, mean(event))

% The joint sample space: the event is everything except a thin region near X = 0
n = 5000;
figure
plot(X(event(1:n)), Y(event(1:n)), '.', X(~event(1:n)), Y(~event(1:n)), 'r.')
hold on
y = linspace(0, 1, 100);
plot((y/2).^3, y, 'k', 'LineWidth', 1.5)
hold off
axis square
xlabel('x')
ylabel('y')
legend('event', 'complement', 'x = (y/2)^3')
grid on
