Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am compiling a calculator where many slider parameters are used to define a value, where the defined value may then be reused to define another value. I am unable able to, or at least been unsuccessful in assigning these values as variables.

I want my coding to be able to refer to a variable (where the variable is an equation) in the sense, however the equation is defined by slider parameters and doesn't initially contain values.

An example of this is a three-step formulation, where the first equation requires parameters defined through sliders, a second equation requires the value from the first equation and another slider parameter, then a third equation requires the value from the second equation and another slider; variables A, C and F are defined from individual sliders like this:

Row[{"Magnification: ", F/C}],
Row[{"Exit Pupil: ", A/(F/C)}],
Row[{"Longest Useful FOV: ", F/(A/(F/C))}],

{{A, 130, "Aperature: "}, 60, 508, 1, Appearance -> "Labeled"},
{{F, 650, "Focal Length: "}, 480, 4064, 1, Appearance -> "Labeled"},
{{C, 32, "Occular Focal Length: "}, 1, 110, 1, Appearance -> "Labeled"},

An easier way to express this would be and how I would like it to display is like this:

Row[{"Magnification: ", F/C = M}],
Row[{"Exit Pupil: ", A/M = E}],
Row[{"Longest Useful FOV: ", F/E}],

I am unable to find a way where this is achieved, the calculator hosts several instances like this however some require the value from another equation without a parameter set from a slider. Some equations are reused multiple times, due to the equations being used there are inconsistencies with formulation until some sliders have changed their values.

I have a working example with complete code if required to see the depth of the formulation, however none of the equations require more than a three-step formulation.

Edit - Full Code

$S1 = Bold;
    $S2 = Orange;

Manipulate[
 N@Grid[{
  {Style["Focal Ratio: ", $S1], Style[FL/AD, $S2]},
  {Style["Dawes Limit: ", $S1], Style[115.824/AD, $S2]},
  {Style["Rayleigh Limit: ", $S1], Style[139.7/AD, $S2]},
  {Style["Gathering Power: ", $S1], Style[(AD/OP)^2, $S2]},
  {Style["Magnification: ", $S1], Style[N[FL/OL, 4], $S2]},
  {Style["Min Magnification: ", $S1], Style[N[AD/OP, 4], $S2]},
  {Style["Exit Pupil: ", $S1], Style[N[AD/(FL/OL), 3], $S2]},
  {Style["True FOV (No F/Stop): ", $S1], Style[N[OF/(FL/OL), 3], $S2]},
  {Style["True FOV (F/Stop): ", $S1], Style[N[(.0957*OL*OF*N[Pi]/180)/FL 57.3, 3], $S2]},
  {Style["Max FOV: ", $S1], Style[N[31.7 180/N[Pi]/FL, 3], $S2]},
  {Style["Longest Useful FOV: ", $S1], Style[N[FL/(AD/(FL/OL)), 5], $S2]},
  {Style["Magnitude Limit: ", $S1], Style[NumberForm[7.5 + 5 Log10[AD/10], 4], $S2]},
  {Style["Ocular Field Stop: ", $S1], Style[N[.0957*OL*OF*N[Pi]/180, 4], $S2]}
 }],
{{AD, 130, "Aperature: "}, 60, 508, 1, Appearance -> "Labeled"},
{{FL, 650, "Focal Length: "}, 480, 4064, 1, Appearance -> "Labeled"},
{{OL, 32, "Occular Focal Length: "}, 1, 110, 1, Appearance -> "Labeled"},
{{OF, 52, "Occular FOV: "}, 40, 72, 1, Appearance -> "Labeled"},
{{OP, 7, "Observer's Pupil: "}, 4, 9, 1, Appearance -> "Labeled"}
]

Example Image

I reworked the layout to a Grid, I will have to adjust the decimals still. There are no more compiling errors, however the instance I want to adjust is being able to refer to a variable say with the Exit Pupil rather than reusing the Mag formula, there are many instances where I have reused the same formulas multiple times, if I can set some of the equations to a variable it will significantly reduce the size and unnecessary complexities. Is there a way I can do this?

share|improve this question
    
Have you looked at Manipulate[ ] in the docs? –  belisarius Dec 12 '13 at 6:40
    
@belisarius I have gone through every HowTo relating to variables and rules and none of them work for my purposes. I will go through Manipulate and see if it's any help. –  Ashley James Dec 12 '13 at 6:46
    
C has built-in meaning too. –  Kuba Dec 12 '13 at 7:24
    
@Kuba Thanks, I thought it did as well as E does. That explains why I get a few of the errors compiling. –  Ashley James Dec 12 '13 at 7:30
    
@Kuba There are no more compiling errors, thank you for correcting me on that and adding that info I have used those in previous notebooks :( Just wanting a method for the original question. –  Ashley James Dec 12 '13 at 8:11
add comment

2 Answers

up vote 4 down vote accepted

I suppose what you ask about recalculating can be done with With or other `scoping construct.

Manipulate[
 With[{mag = FL/OL, minmag = AD/OP},
      Grid[
       MapAt[ NumberForm[N@#, {\[Infinity], 4}] &,
              {{"Gathering Power: ", (minmag)^2}, 
               {"Magnification: ", mag}, 
               {"Min Magnification: ", minmag},
               {"Exit Pupil: ", AD/mag}, 
               {"True FOV (No F/Stop): ", OF/mag}, 
               {"Max FOV: ", (31.7*180)/(Pi*FL)}, 
               {"Longest Useful FOV: ", mag FL/AD}}
            , {All, 2}]
        , ItemStyle -> {{Bold, Orange}}, Alignment -> {{Left, "."}}]
     ]
     , 
      {{AD, 130, "Aperature: "}, 60, 508, 1, Appearance -> "Labeled"}, 
      {{FL, 650, "Focal Length: "}, 480, 4064, 1, Appearance -> "Labeled"}, 
      {{OL, 32, "Occular Focal Length: "}, 1, 110, 1, Appearance -> "Labeled"}, 
      {{OF, 52, "Occular FOV: "}, 40, 72, 1, Appearance -> "Labeled"}, 
      {{OP, 7, "Observer's Pupil: "}, 4, 9, 1, Appearance -> "Labeled"}]

enter image description here

share|improve this answer
    
That works perfectly @Kuba, it's very neat and also fixed my decimal problem. The way you included the style formatting as well, this is a big step further in cleaning the code up. I really like the way you presented this example. Thank you greatly in being intuitive I'm learning a lot from what you provided. –  Ashley James Dec 12 '13 at 15:05
    
@AshleyJames That's great, I was hoping that you will find this usefull. Manual styling may be discouraging. Good luck with your project! :) –  Kuba Dec 12 '13 at 17:39
add comment

May be I am missing something but Manipulate is designed to automatically re-evaluate when one variable in its expression changes.

Manipulate[
N@Grid[{
  {"Magnification: f/c = ", f/c},
  {"Exit Pupil: a/m =", a/(f/c)},
  {"Longest Useful FOV: f/e =", f/(a/(f/c))}
  }],
 {{a, 130, "Aperature: "}, 60, 508, 1,Appearance -> "Labeled"}, 
 {{f, 650, "Focal Length: "}, 480, 4064, 1,Appearance -> "Labeled"}, 
 {{c, 32, "Occular Focal Length: "}, 1,110, 1, Appearance -> "Labeled"}
 ]

Mathematica graphics

share|improve this answer
    
Sorry, It should read Row[{"Magnification: ", N[f/c]}], for example. –  Ashley James Dec 12 '13 at 6:49
    
@AshleyJames, ok add N@Grid –  Nasser Dec 12 '13 at 6:52
    
Nice idea, it will only work for the example, in reality I am using multiple columns and rows; I have demonstration images on the right side and values on the left side in my content. –  Ashley James Dec 12 '13 at 7:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.