Lenses Equation - Reiterating for 5 Lenses.

5 views (last 30 days)
Billy Le Grave
Billy Le Grave on 10 Apr 2019
Commented: Billy Le Grave on 10 Apr 2019
I am trying to reiterate the equation to find the position of an image for a single lens up to 5 lenses. The equation for a single lens is , where , and . As the equation is iterated forwards, A, B and C change and become more complicated, hence the reqierment for MATLAB. When i run my code I get the 'Index exceeds matrix dimensions" error. Any help would be greatly appreciated, thank you in advance.
n = 5; % No. of Lenses
x0 = 0; % Source Position [cm]
xi = (1:n); % Create Array
xi(1) = 3.9; % Lens Position [cm]
xi(2) = 10.9;
xi(3) = 23.1;
xi(4) = 31.8;
xi(5) = 41.2;
f = (1:n); % Focal Lengths [cm]
f(1) = 0.5;
f(2) = -1.0;
f(3) = 2.0;
f(4) = -2.5;
f(5) = 1.0;
a = (xi);
b = f + xi;
c = xi - f;
A = zeros(1,n); % Create Array of Zeros
B = zeros(1,n);
C = zeros(1,n);
xi1 = (A(1)-(B(1)*x0))/(C(1)-x0);
for i = 2,n;
A(i) = (((a(i).^2)*C(i-1))-(b(i)*A(i-1)))/((n(i)*C(i-1))-B(i-1));
B(i) = ((-b(i)*B(i-1))-(a(i).^2))/(((a(i).^2)*C(i-1))-B(i-1));
C(i) = ((c(i)*C(i-1))-A(i-1))/((c(i)*C(i-1))-B(i-1));
end
Image = (A(n)-(B(n)*x0))/(C(n)-x0)
  3 Comments
Stephen23
Stephen23 on 10 Apr 2019
Edited: Stephen23 on 10 Apr 2019
There is a bug is where you try to access n(i) (but n is a scalar, you probably meant to use another variable here).
Note that the vector defintions are far too complex. Simpler:
xi = [3.9,10.9,23.1,31.8,41.2];
f = [0.5,-1.0, 2.0,-2.5, 1.0];
n = numel(f);

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!