1 | initial version |
The following code produces the beats you are looking for.
var('t')
f1=110
f2=104
fs=(f1-f2)
fr=(f1+f2)/2
t1=2/fs
p = plot(a*cos(pi*fs*t)*sin(2*pi*fr*t),(t,0,t1),color='red')
p+=plot([a*cos(pi*fs*t),-a*cos(pi*fs*t)],(t,0,t1))
p.show()
2 | added updated interact code |
The following code produces the beats you are looking for.
var('t')
f1=110
f2=104
fs=(f1-f2)
fr=(f1+f2)/2
t1=2/fs
p = plot(a*cos(pi*fs*t)*sin(2*pi*fr*t),(t,0,t1),color='red')
p+=plot([a*cos(pi*fs*t),-a*cos(pi*fs*t)],(t,0,t1))
p.show()
The code below produces an interact that is probably more like want you want. Note that the slider
command lets you initialize the sliders.
var('t')
print "Choose 1 for Lissajous curve and 2 for beat"
@interact
def choise(v =(1..2)):
if v==1:
@interact
def lissa(delta =slider(-pi,pi,0.1,1),a = slider(1,10,1,6),b = slider(1,10,1,2)):
p = parametric_plot((cos(a*t+delta),cos(b*t)),(t,0,5*pi))
p.show()
else:
@interact
def beat(a = slider(0,5,1,1), f1=slider(0,150,10,110),f2=slider(0,150,10,100)):
fs=(f1-f2)
fr=(f1+f2)/2
t1=2/fs
p = plot(a*cos(pi*fs*t)*sin(2*pi*fr*t),(t,0,t1),color='red')
p+=plot([a*cos(pi*fs*t),-a*cos(pi*fs*t)],(t,0,t1))
p.show()
Here's a link to the code using the Sage single-cell server.