%%
clear
close all


% Running things in code (highlight lines, press F9 to run)
5
a = 5
b = [6 7 8]
c = 1:10
d = 0:.05:1
% Note that the variables appear in the workspace


% We can access individual components of arrays using the () brackets
% As above, we create arrays with [] brackets
d(10)
d(end)
d(1:5)

a + b
e = a+d

% Notice each variable and command is being displayed in the command window
% This can quickly get annoying.  Use a ; at the end of the line to
% suppress output

8;
f = 8;
g = f+d;
g

disp(g);
%% Lets look at manipulating arrays and plotting them
clear
close all

x = 0:.01:5;
length(x) % Gives the largest dimension of matrix

y = cos(x);
length(y)

figure
plot(x,y)


% Lets manipulate the wavelength
lambda = 0.5; % This will be the wavelength
k = 2*pi/lambda; % This changes wavelength to wave number (k)

y2 = cos(k*x); 

figure
plot(x,y2)

% Change the wavelength, and replot
lambda2 = 1;
k2 = 2*pi/lambda2;

y3 = cos(k2*x);

figure
plot(x,y3,'r')

% Playing with the plot command
figure
plot(x,y2,'b') % It will plot with the color 'blue'
hold on
plot(x,y3,'g') % Color 'green'
plot(x,y,'k--') % Color 'black' and dashed
hold off


%% Lets calculate photon energy as a function of wavelength
clear
close all

hc = 1240; % Energy in ev-nm
lambda = 400:700; % Visible wavelength
photonEnergy = hc./lambda;

figure
plot(lambda,photonEnergy)
xlabel('Wavelength (nm)')
ylabel('Energy (eV)')

% Compare that to XRays
lambdaX = .01:.01:10; % I looked up online the wavelength of xrays 
xrayEnergy = hc./lambdaX;
figure
plot(lambdaX,xrayEnergy)
xlabel('Wavelength (nm)')
ylabel('Energy (eV)')

% Use the zoom button to look closer at xray energy values

%% Lets plot out Cauchy equations
% Cauchy equations approximate the changing index of refraction as a
% function of wavelength.

clear
close all
lambda = 400:700; % Wavelength range across visible spectrum in nm
% Cauchy constants
B = 1.50;
C = 4200;

nLambda = B + C./(lambda.^2);

figure
plot(lambda,nLambda)
xlabel('Wavelength (nm)')
ylabel('Index of refraction')
title('BK7 glass dispersion')



