% Fresnel equations
% for n_i = 1 (air), n_t = 1.5 (glass)

n_i = 1;
n_t = 1.5;
n_ti = n_t/n_i;

theta_i = linspace(0,pi/2);
theta_t = asin(1/n_ti*sin(theta_i));


% Transverse electric mode
r_te = (cos(theta_i)-sqrt(n_ti^2-sin(theta_i).^2))./...
        (cos(theta_i)+sqrt(n_ti^2-sin(theta_i).^2))
t_te = 2*n_i*cos(theta_i)./...
        (n_i*cos(theta_i)+n_t*cos(theta_t));

subplot(211);
plot(theta_i,r_te); hold on;
plot(theta_i,t_te,'r');
xlim([0 pi/2]);
xlabel('Incident angle, \theta_i_i');
ylabel('r [blue]; t [red]');
title('Reflection and transmission coefficients for TE wave');
grid on;

% Transverse magnetic mode
r_tm = (n_ti^2*cos(theta_i)-sqrt(n_ti^2-sin(theta_i).^2))./...
        (n_ti^2*cos(theta_i)+sqrt(n_ti^2-sin(theta_i).^2));
t_tm = 2*n_i*cos(theta_i)./...
        (n_t*cos(theta_i)+n_i*cos(theta_t));
    
subplot(212);
plot(theta_i,r_tm); hold on;
plot(theta_i,t_tm,'r');
xlim([0 pi/2]);
xlabel('Incident angle, \theta_i_i');
ylabel('r [blue]; t [red]');
title('Reflection and transmission coefficients for TM wave');
grid on;



