
Tim Waters
By: a guest on Jul 27th, 2009 | syntax:
None | size: 2.21 KB | hits: 13 | expires: Never
eps = .0001
%can also customize; input('Enter the tick-size (epsilon) ');
n1 = 1 %input('Enter the index of refraction in region containing A ');
n2 = 1.5 %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
%************************plot results *************************************
m = a(1)+b(1); %slope of straiht line path connecting a to -b
hold on;
%allows you to add more things to the plot
y_ab = -m*c + a(1);
plot(c,y_ab
) %plots straight line path
plot(c
(1:
i.html">i),y_ac
) %plots computed shortest path from A to C
text(0,a(1),'Point A'); %labels via text(x,y,'string')
text(1,-b(1),'Point -B');
d_ab =
sqrt(1+
(b
(1
)+a
(1
))^2
);
%dist between pts A and -B
i_ab=
floor((a
(1
)/m
)/
eps);
%location of straight line path
title({'Straight Line Path and Least Time Path for n1/n2 interface';
sprintf('Straight line path dist = %0.5g ',d_ab
);
sprintf('Least time path opl = %0.5g ',opl_min
);
sprintf('Straight line path opl = %0.5g ',opl
(i_ab
))})
%Check Answer with Snell's Law
n1/n2
xlabel({'Snells Law says n_i/n_f = (1-c)d_{ac}/(c*d_{cb})';
sprintf('Thus compare n_i/n_f = %0.5g ',n1/n2
);
sprintf('with (1-c)d_ac/(c*d_cb) = %0.5g ',answr
)});