ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 08 May 2018 20:13:06 -0500One interact slider for multiple functionshttp://ask.sagemath.org/question/42294/one-interact-slider-for-multiple-functions/Hello everyone, I'm new to Sagemath and Python in general, so forgive me if this is trivial.
I am trying to create one slider, which can control several functions, which are all based on the same variable, at the same time, here's an example
----------
def function_a(x):
return x + 1
def function_b(x):
return x + 2
mySlider = widgets.FloatSlider(min=0.1, max=10.0, step=0.1, value=1.0)
interact(function_a(x),function_b(x), x=mySlider) # calling both functions in interact is not allowed
----------
Me and friends from university tried for several hours now, with no satisfying result. The example is just to ilustrate the challenge, we never expected it to work.
Thanks in advance!
Tue, 08 May 2018 10:46:43 -0500http://ask.sagemath.org/question/42294/one-interact-slider-for-multiple-functions/Answer by calc314 for <p>Hello everyone, I'm new to Sagemath and Python in general, so forgive me if this is trivial.</p>
<p>I am trying to create one slider, which can control several functions, which are all based on the same variable, at the same time, here's an example </p>
<hr>
<p>def function_a(x):
return x + 1</p>
<p>def function_b(x):
return x + 2</p>
<p>mySlider = widgets.FloatSlider(min=0.1, max=10.0, step=0.1, value=1.0)
interact(function_a(x),function_b(x), x=mySlider) # calling both functions in interact is not allowed</p>
<hr>
<p>Me and friends from university tried for several hours now, with no satisfying result. The example is just to ilustrate the challenge, we never expected it to work.</p>
<p>Thanks in advance!</p>
http://ask.sagemath.org/question/42294/one-interact-slider-for-multiple-functions/?answer=42298#post-id-42298I'm not sure exactly what you are aiming for, but in a sagews worksheet in CoCalc, you can do the following.
@interact
def go(f1=x+1,f2=x+2, a=slider(1,5,1,default = 3)):
p1=plot(a*f1,(x,-3,3))
p2=plot(f2+a,(x,-3,3))
show(p1+p2)Tue, 08 May 2018 20:13:06 -0500http://ask.sagemath.org/question/42294/one-interact-slider-for-multiple-functions/?answer=42298#post-id-42298