0
$\begingroup$

I have this manipulate

Manipulate[
 If[filllower > fillupper, filllower = fillupper]; 
 Grid[{{Show[
     Plot[(Sqrt[2] Sin[n \[Pi] x])^2, {x, 0, 1}, 
      PlotRange -> {{0, 1}, {0, 2}}], 
     If[filllower == fillupper, 
      Plot[(Sqrt[2] Sin[n \[Pi] x])^2, {x, 0, 1}, 
       PlotRange -> {{0, 1}, {0, 2}}], 
      Plot[(Sqrt[2] Sin[n \[Pi] x])^2, {x, filllower, fillupper}, 
       Filling -> 0, PlotRange -> {{0, 1}, {0, 2}}]], 
     AxesLabel -> {"x", "probability density"}, ImageSize -> 500, 
     AspectRatio -> .25, 
     PlotLabel -> 
      Grid[{{Row[{Style[
            "probability = " <> 
             ToString[
              NumberForm[
               Abs[Integrate[(Sqrt[2] Sin[n \[Pi] x])^2, {x, 
                  filllower, fillupper}]], {4, 3}, 
               NumberPadding -> {"", "0"}, 
               ExponentFunction -> (Null &)]], "Label"], 
           Style["  |  ", GrayLevel[.5]], 
           Style["quantum number = " <> ToString[n], "Label"]}]}}], 
     ImagePadding -> {{50, 50}, {30, 50}}]}, {Plot[(Sqrt[2] Sin[
        n \[Pi] x]), {x, 0, 1}, Frame -> True, ImageSize -> 500, 
     PlotRange -> {-Sqrt[2], Sqrt[2]}, 
     PlotLabel -> Style["wave function of the electron", "Label"], 
     AspectRatio -> .3, ImagePadding -> {{50, 50}, {50, 30}}]}}], 
 "X3" -> {{n, 1, "quantum number"}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 
   ControlType -> SetterBar}, 
 "X" -> {{filllower, 0, "lower limit"}, 0, 1, Appearance -> "Labeled"},
 "Y" -> {{fillupper, 1, "upper limit"}, 0, 1, 
   Appearance -> "Labeled"}]

but i want to have a condition ... for n odd ( 2 4 6 8 10, continuous this way ...

but for n even ( 1 3 5 7 ), changes all sin by cos - this is the only change .. and the same plot ... so for n odd, continuous sin and sin^2 , and for n even, change sen by cos and cos^2 ... how can i do that ? and if its possibles, up to the plots , in the manipulate, show the expression and show modifyng the n value.

$\endgroup$
2
  • $\begingroup$ Presumably it's a typo when you say "n odd ( 2 4 6 8 10 ... " ? (Same for even.) $\endgroup$
    – jjc385
    Commented Nov 14, 2017 at 19:24
  • 2
    $\begingroup$ The answers given to this question may help you. $\endgroup$
    – m_goldberg
    Commented Nov 14, 2017 at 20:11

1 Answer 1

2
$\begingroup$

I'm not completely sure I understand what you seek. Does this work?

Manipulate[If[filllower > fillupper, filllower = fillupper];
 With[{f = If[EvenQ@n, Sin, Cos]},
  Grid[{{Show[
      Plot[(Sqrt[2] f[n \[Pi] x])^2, {x, 0, 1}, 
       PlotRange -> {{0, 1}, {0, 2}}], 
      If[filllower == fillupper, 
       Plot[(Sqrt[2] f[n \[Pi] x])^2, {x, 0, 1}, 
        PlotRange -> {{0, 1}, {0, 2}}], 
       Plot[(Sqrt[2] f[n \[Pi] x])^2, {x, filllower, fillupper}, 
        Filling -> 0, PlotRange -> {{0, 1}, {0, 2}}]], 
      AxesLabel -> {"x", "probability density"}, ImageSize -> 500, 
      AspectRatio -> .25, 
      PlotLabel -> 
       Grid[{{Row[{Style[
             "probability = " <> 
              ToString[
               NumberForm[
                Abs[Integrate[(Sqrt[2] f[n \[Pi] x])^2, {x, filllower,
                    fillupper}]], {4, 3}, NumberPadding -> {"", "0"}, 
                ExponentFunction -> (Null &)]], "Label"], 
            Style["  |  ", GrayLevel[.5]], 
            Style["quantum number = " <> ToString[n], "Label"]}]}}], 
      ImagePadding -> {{50, 50}, {30, 50}}]}, {Plot[(Sqrt[2] f[
         n \[Pi] x]), {x, 0, 1}, Frame -> True, ImageSize -> 500, 
      PlotRange -> {-Sqrt[2], Sqrt[2]}, 
      PlotLabel -> Style["wave function of the electron", "Label"], 
      AspectRatio -> .3, ImagePadding -> {{50, 50}, {50, 30}}]}}]
  ], 
 "X3" -> {{n, 1, "quantum number"}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 
    10}, ControlType -> SetterBar}, 
 "X" -> {{filllower, 0, "lower limit"}, 0, 1, 
   Appearance -> "Labeled"}, 
 "Y" -> {{fillupper, 1, "upper limit"}, 0, 1, 
   Appearance -> "Labeled"}]
$\endgroup$
1
  • $\begingroup$ This looks like it was a drive-by-question, as the OP did not return back after asking. $\endgroup$
    – Nasser
    Commented Dec 15, 2017 at 1:55

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.