2
$\begingroup$

Helly everybody,

I will try to keep this as simple as possible.

  1. I have a function which looks like this:

    Min[T_, E_, D_] := Module[ ..... List = {...} ];
    

In any case this function gives me a list that looks like this {1,2, 1, 4,5, 2,1} etc. (Actually D determines the number of entries in this list)

  1. I use Listplot to plot this list.

    ListPlot[Min[T, E, D], PlotRange -> {Automatic, {0,  0.5}}]
    
  2. I use Manipulate to be able to manipulate any of these 3 Variables.

    Manipulate[ListPlot[Min[...], {T, 1, 20}, {D, 10, 20}, {E, 1, 20}]
    

    Everything worked perfectly and dandy, but I ran into one problem. E has a dynamic limit that changes when I change D or T and few other factors.

  3. So in order to be able to calculate the dynamic limit ofE, I had to write a few new lines in the old Min.

    So now it looks something like this:

    Min[T_, E_, D_] := 
      Module[Emax = T + D  + a; List = {...}];   
    

    where a is a variable only used in that function

Even though Emax is getting calculated correctly, I just cannot use it outside of the function.

When I plug it into the Manipulate stuff like this:

ListPlot[Min[...], {T, 1, 20}, {D, 10, 20}, {E, 1, Emax}] 

the code does not know what Emax is.

Any ideas what I can do?

I need to use a variable from inside a function as limit for a Manipulate.

$\endgroup$
  • $\begingroup$ Min, List, N, D and E are built-in and (mostly) protected symbols. Can you prepare a small working example which shows the problem? It is not clear if mentioned symbols are the problem or the exact syntax you use (which is not shown either). $\endgroup$ – Kuba Aug 2 '18 at 13:32
1
$\begingroup$

You can try something like this:

Manipulate[emax = Quotient[max, 3]; ListPlot[Prime[Range[emax]]], {max, 10, 20}]

Manipulate allows ; separated statements before the one that produces the output and treats all the variables as dynamic

$\endgroup$
  • $\begingroup$ This worked quite welll. But sadly not as good as I have wished. I was able to determine the Variable with the desired value just as you said, in a seperate statement before the one that produces the output. Let's call this Variable A. Now I'm in an odd situation where I used A for 2 things: $\endgroup$ – Benjamin Jabl Aug 7 '18 at 10:31
  • $\begingroup$ 1. I used it as Epiloge to be displayed next to the Plot so I can see how it changes. Epilog -> { Text[Style[A "A", ...]}; 2. I used it as a Limit for the Manipulate of one of the Variables. Filling -> Axis, PlotRange -> {Automatic...}, {D, 1, A}]; It works for the Epiloge. But it does not work for the limit. As I change the other 2 variables I see A changing on the Epilogue but the Limit for Variable D stays constant. Why ? I was hoping that it would update the Value for the Limit aswell :/ $\endgroup$ – Benjamin Jabl Aug 7 '18 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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