1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Matlab code for geometrical optics

  1. Jun 16, 2013 #1
    Hello all,

    i have frustrating task in my lab...

    i have to generate a code in MATLAB that will get the focal length and the object distance from the lens, i.e image (1000X1000 pixels).
    transfer it through the lens and, for the output it should be the result of it: inverse,magnified/shrinked version of the image. of course depends on the focal & distance of the object.
    this should be done considering that the lab is on geometrical optics...

    any help/reference would be appreciated

    my thought was to form a incidence matrix that will be transformed after multiplication with transfer matrix (Air,Lens,Air) and apply this matrix to the image matrix.
  2. jcsd
  3. Jun 16, 2013 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    Lets make sure I understand you:
    You have been given an image - and you need to know how far the object is.

    Presumably you know something about the lens-system and/or the object?

    My immediate approach would be to run the optics backwards - since geometric optics is reversible.
    I'd also just pick one point on the image as the "arrow head".

    But yeah - transfer matrix etc.
  4. Jun 17, 2013 #3
    we know all about the lens system: f,distance of from the object,distance of the image.
    i'm pretty lack of knowledge how to implement it with matlab. need for some sort of algorithm of how to do it.
  5. Jun 17, 2013 #4

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    I'm not sure I see the problem - you know the image and object distances, the focal length, so you know the magnification (you have a formula for that?) So what is wrong with a script that takes these details as the input, calculates the magnification, and interprets it?

    i.e. how would you perform this task on paper?

    But now I suspect that I have not understood the problem ... what will the program take as input, what is to be assumed (i.e. is it always the same lens? Is it a thin lens? What?), and what is the output supposed to be? Try to be more careful in your description.
  6. Jun 17, 2013 #5
    ok, sorry,
    you understood very well the problem, but the implementation is not so obvious (for me i guess...).
    as an input i have:
    1)1000X1000 image.
    2)distance of the image from the lens
    3)focal length

    now i can calculate as you said the distance of the image after the lens & the magnification.
    that's the easy part.
    now i have to apply some algorithm that will take the original image and will transform it to the expected image,
    let's say that magnification was calculated and it equals 2.
    so i'm expecting to see a 2000x2000 magnified image upside down and mirrored.
    how do i map each of indices of the original image to the expected image ?
    example: the [(1,1)] pixel should be mapped to [(2000,2000)] pixel of the magnified version of the image.
  7. Jun 17, 2013 #6

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

  8. Jun 17, 2013 #7
    thought to do it in more "analytic" way...
    i accomplished the assignment as you suggested, but in this way there is no "lens" in the code only the outcomes.

    Code (Text):
    %Input object distance do
    %Input focal length of lens f
    % Input distance behind lens z
    %Input object ray coordinates ro
    To=[ 1 ,do;0,1 ];
    Ti=[ 1 ,z;0,1 ];
    %Check for determinant of overall matrix S
    %"image" ray coordinate is ri
    Output from MATLAB
    detS =
    ri =
    variation of this code.
  9. Jun 17, 2013 #8

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    Well done - sometimes it's just a mater of kickstarting the old grey matter.
  10. Jun 19, 2013 #9
    thanks for the help, Simon :)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted