
Tim Waters
By: a guest on Jul 27th, 2009 | syntax:
None | size: 2.26 KB | hits: 14 | expires: Never
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%For the blog 'Brute Force Physics' by Tim Waters
%filename:stationary.m
%reference: Feynman Lectures 26-4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
eps= .00001
%input('Enter the tick-size (epsilon) ');
n1 = 1 %input('Enter the index of refraction in region containing A ');
n2 = 1.33 %input('Enter the index of refraction in region containing B ');
mirror_axis = 0:
eps:
1;
%cut (0,1) into grid points
c = mirror_axis'; %creates a column vector
a =
ones(length(c
),1
)*
rand;
%ones(rows,columns) returns a matrix of 1s
%Compute the optical path length, opl
d_ac =
sqrt(a.^2 + c.^2
);
d_cb =
sqrt((1-c
).^2 + b.^2
);
opl_ac=n1*d_ac;
opl_cb=n2*d_cb;
opl = opl_ac + opl_cb;
end
% i now contains the location of opl_min in the vector opl
%**************************************************************************
%numerical analysis
m = a(1)+b(1); %slope of straiht line path connecting a to -b
i_ab=
floor((a
(1
)/m
)/
eps);
%vector index of straight line path
x_ab = a(1)/m;
plot(c,opl
) %plots opl vs. x
%place a black * at the straight line path location:
plot(x_ab,opl
(i_ab
),
'k*')
%label it
text(x_ab,opl(i_ab),...
' \leftarrow Straight line opl',...
'EdgeColor','black',...
'LineWidth',1,...
'LineStyle',':');
' \leftarrowMinimum opl',...
'EdgeColor','red',...
'LineWidth',1,...
'LineStyle',':');
%compute the 1st and 2nd derivatives around the two points
[dx,ddx
]=variation
(opl,i_ab,
eps);
title({'Numerical Analysis: 1st and 2nd Derivatives:';
sprintf('1st variation at point c = %0.5f ',dx_c
);
sprintf('2nd variation at point c = %0.5g ',ddx_c
);
sprintf('1st variation at straight line path = %0.5g ',dx
);
sprintf('2nd variation at straight line path = %0.5g ',ddx
)})