They are all very different, although all return a similar hash of 
arguments.


Here is an example...

def vergence_v
  u = (rand(2..6)).round(2)
  u_vergence =((1/(u*0.01)).round(2))
  p = rand((u_vergence + 0.1) ..(u_vergence + 0.7)).round(2)
  v_vergence = (p - u_vergence).round(2)
  v = (1/v_vergence).round(2)

  question = "A slide is placed #{u} cm to the left of a +#{p} D lens. 
At what distance (in meters) will the screen need to be placed to the 
right of the lens to have the image be in perfect focus?"

  answer = "Answer = #{v} meters"

  anno = "Solution:

    Use the formula U + P = V.

    U = Vergence of light rays from the object entering the lens
    P = Power of the lens in diopters
    V = Vergence of light rays leaving the lens and forming the image

    where u = #{u} cm
          P = #{p} D

    (1) Solve for V
        V = U + P

    (2) Solve for U
        Since Vergence = 1/distance in meters, we need to convert all 
units from centimeters to meters.

             u = #{u} cm = #{u} X 0.01 = #{((u)*0.01).round(2)} m

        U is negative because it is a real object and light rays DIVERGE 
from REAL objects

             U = -1.0/#{(u*0.01).round(2)}m = 
#{(-1.0/(u*0.01)).round(2)}D

    (3) Solve for V

            V = U + P = #{(-1.0/(u*0.01)).round(2)}D + #{p}D = 
#{((-1.0/(u*0.01)) + p).round(2)}D

    (4) Solve for v

            v = 1/V = #{(1/v_vergence).round(2)}cm"

  formatted = {"question_1" => question, "answer_1" => answer, "anno_1" 
=> anno}

end

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to