3
$\begingroup$

In the code below the value displayed next to the slider may be correct, and should be the result of The value of x for cyL and the value of x for change at the slider position. Slider position 0 should provide the first values for x in these lines. Now if I evaluate xoutside of the function after moving the sliders, it only returns the slider position and not the value of x from the function. How can I get the variable to return the correct value for each slider? Thanks!

cyL[x_] := 
  58.770000000000046` - 3.557000000000158` x - 
   3.525333333333144` x^2 + 4.987999999999908` x^3 - 
   1.3386666666666487` x^4;

cyA[y_] := -35.13365403304179` - 0.009572400388682331` y + 
   0.08989310009715228` y^2 - 0.01687074829931251` y^3;

change[x_] := -0.17006802721089645` + 62.92517006802724` x - 
   6.802721088435384` x^2;

Column[{{Slider[Dynamic[x, Automatic]], 
   Dynamic[cyL[change[x]]]}, {Slider[Dynamic[g, Automatic]], 
   Dynamic[cyA[change[g]]]}}]
$\endgroup$
  • $\begingroup$ Works fine for me on OS X MMA 8.0.4. I get 59.2473 for the first number at slider position 0 and -35.1293 for the second. $\endgroup$ – Timo Mar 9 '12 at 12:58
  • $\begingroup$ for the value of x or the displayed value of the slider? If I check the value of x at any slider position, I just get the slider position, I'm also on MM 8.04 OSX Try evaluating x outside of the function. That produces the slider position, I need the displayed value. $\endgroup$ – R Hall Mar 9 '12 at 13:05
  • $\begingroup$ Aaah. I see. you want to access the value of cyL[x] outside of the Slider. Am I correct? $\endgroup$ – Timo Mar 9 '12 at 13:25
  • $\begingroup$ Yes, well the result of x for cyL[change[x] yes thanks. I need to pass that number outside of the Dynamic to another function and then to a plot. $\endgroup$ – R Hall Mar 9 '12 at 13:31
  • $\begingroup$ I meant the value displayed next to the slider. I'm sorry if I didn't understand your question correctly. Do you want to display x, change[x], cyL[x]. cyL[change[x]], or something else? Or do you want the access any (and which) of those outside of the slider? $\endgroup$ – Timo Mar 9 '12 at 13:33
6
$\begingroup$

After your last comment, maybe you should assing the value of cyL[change[x]] to another variable in the dynamic, and use it outside. Something like this:

enter image description here

$\endgroup$
  • $\begingroup$ Thanks @FJRA! Works perfectly!! $\endgroup$ – R Hall Mar 13 '12 at 18:00

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.