Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
MatlabMain/lens_calculator.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
110 lines (92 sloc)
3.31 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% simulations for optical systems | |
% 2-lenses system | |
% numerical simulation of magnification | |
f_1 = [-1000:1000]; | |
f_2 = [1:1000]; | |
u_1 = 1:500; | |
% single lens | |
v_1 = zeros(length(f_1),length(u_1)); | |
for i = 1:length(f_1) | |
for ii= 1:length(u_1) | |
v_1(i,ii) = (f_1(i)*u_1(ii)) / (u_1(ii)-f_1(i)); | |
end | |
end | |
figure, p=plot(v_1(:,50:50:500)); hold on | |
legend(string_array,'Location','SouthWest') | |
xlabel('focal length, mm') | |
ylabel('virtual image distance, mm') | |
% two lens system: magnification | |
m = zeros(length(f_1),length(f_2),length(u_1)); | |
d = zeros(length(f_1),length(f_2),length(u_1)); | |
for i = 1:length(f_1) | |
for ii = 1:length(f_2) | |
for iii = 1:length(u_1) | |
m(i,ii,iii) = (150*(f_1(i)*u_1(iii))/(u_1(iii) - f_1(i))) / (u_1(iii) * 150*f_2(ii)/(150-f_2(ii))); | |
end | |
end | |
end | |
% visualize exemple | |
m1 = squeeze(m(:,:,400)); | |
figure, %subplot(121), | |
imagesc(1./m1,[-5 5]), colorbar, axis square, | |
ylabel('focal length of lens 1, mm') | |
xlabel('focal length of lens 2, mm') | |
title('de-magnification factor, object size to image size, u1 = 400 mm, v2=150 mm','FontSize',12,'FontWeight','bold') | |
subplot(122), imagesc( (abs(m1)>=1/4).* (abs(m1)<=1/3) ), axis square | |
ylabel('focal length of convex lens, mm') | |
xlabel('distance screen to first lens, mm') | |
title('bands of demagnfication factor between 3x and 4x') | |
% find size of region of space with right magnification | |
% as a function of object distance to first lens | |
high_cutoff = 3.5; | |
low_cutoff = 3; | |
magnification_binary = zeros(size(m)); | |
magnification_region_size = zeros(size(m,3)); | |
for iii = 1:length(u_1) | |
magnification_region_size(iii) = numel(find((abs(squeeze(m(:,:,iii)))>=1/high_cutoff).* ... | |
(abs(squeeze(m(:,:,iii)))<=1/low_cutoff)))/(size(m,1)*size(m,2)); | |
magnification_binary(:,:,iii) = (abs(squeeze(m(:,:,iii)))>=1/high_cutoff).* ... | |
(abs(squeeze(m(:,:,iii)))<=1/low_cutoff); | |
end | |
% two lens system: distance between lenses, as function of focal lengths, | |
% and object position | |
% initial conditions, mm | |
v_2 = 150; | |
% u1 = 30; | |
d = zeros(length(f_1),length(f_2),length(u_1)); | |
for i = 1:length(f_1) | |
for ii = 1:length(f_2) | |
for iii = 1:length(u_1) | |
d(i,ii,iii) = f_2(ii)*v_2/(v_2-f_2(ii)) - f_1(i)*u_1(iii)/(u_1(iii)-f_1(i)); | |
end | |
end | |
end | |
d1 = squeeze(d(:,:,50)); | |
figure, %subplot(121), | |
imagesc(d1,[-500 500]), colorbar, axis square, | |
ylabel('focal length of lens 1, mm') | |
xlabel('focal length of lens 2, mm') | |
title('distance between lenses, u1= 50 mm') | |
subplot(122), imagesc( (abs(m1)>=1/4).* (abs(m1)<=1/3) ), axis square | |
ylabel('focal length of convex lens, mm') | |
xlabel('distance screen to first lens, mm') | |
title('bands of demagnfication factor between 3x and 4x') | |
% binarize solutions | |
m_binary = zeros(length(f_1),length(f_2),length(u_1)); | |
for iii = 1:length(u_1) | |
m_binary(:,:,iii) = (abs(m(:,:,iii))>=1/4).* (abs(m(:,:,iii))<=1/3); | |
end | |
figure, contour3(u_1,f_2,1./abs(squeeze(m(60,:,:))),1000) | |
ftest = [60,75,100,125,150,175,200,250,300,400,500,750] | |
for j = 1:length(ftest) | |
figure, imagesc(1./abs(squeeze(m(ftest(j),:,:)))), title(['f1 = ', num2str(ftest(j))]) | |
end | |
% minimize distance between lenses | |
u1 = 1:100; | |
f1 = 60:5:1000; | |
d = zeros(length(f1),length(u1)); | |
for i = 1:length(f1) | |
for ii = 1:length(u1) | |
d(i,ii) = f1(i)*u1(ii) / (u1(ii)-f1(i)); | |
end | |
end | |