1
$\begingroup$

Screenshot

Trying to display the value of wl3 in the top right box, value should change while manipulating values of wl1 and wl2 in the two boxes to its left, how do I do it? Code for reference

wl3[wl1_, wl2_] := wl1 + wl2;
θrefr[θinc_, n1_, n2_] := θinc*n1/n2;
Manipulate[
 Grid[
  {{Label,
    {Manipulate[wl1, {wl1, 1, 2, Appearance -> "Labeled"}, 
      FrameLabel -> "Wavelength1"]},
    {Manipulate[wl2, {wl2, 1, 2, Appearance -> "Labeled"}, 
      FrameLabel -> "Wavelength2"]},
    {wl3[wl1, wl2]}}]
$\endgroup$

1 Answer 1

3
$\begingroup$

Trying to display the value of wl3 in the top right box

I would not use Manipulate inside Manipulate. You can do all this with one manipulate.

enter image description here

The idea is to use None for Manipulate, and then use Grid to layout both the control variables and also the output which normally goes where None now sits. But to do this, you need to use Dynamic for the output part.

wl3[wl1_, wl2_] := wl1 + wl2;
Manipulate[
 None,
 Grid[{
   (*first two grids are control variables *)
   {Grid[{{"Wavelength1", 
       Manipulator[Dynamic[wl1, {wl1 = #} &], {0, 1, .1}, 
        ImageSize -> Tiny]}, {Dynamic[wl1]}}, Frame -> True],

    Grid[{{"Wavelength2", 
       Manipulator[Dynamic[wl2, {wl2 = #} &], {0, 1, .1}, 
        ImageSize -> Tiny]}, {Dynamic[wl2]}}, Frame -> True],

    (*this is the output, must be dynamic *)
    Grid[{{"wl1+wl2"},
      {Dynamic@Row[{ wl1,"+",wl2," = ",wl3[wl1,wl2]}]}},Frame->True]

    }}, Spacings -> {1, 1}, Background -> White
  ],

 Alignment -> Center, ImageMargins -> 0, FrameMargins -> 1, 
 ContentSize -> {0}, SynchronousInitialization -> True, 
 ContinuousAction -> True, Alignment -> Center, Paneled -> True, 
 Frame -> False
 ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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