14786
Comment:
|
← Revision 48 as of 2020-06-05 20:32:41 ⇥
12926
negative number in Venn diagram
|
Deletions are marked like this. | Additions are marked like this. |
Line 17: | Line 17: |
self.sr = 44100 | self.sr = int(4100) |
Line 31: | Line 31: |
html('$\cos(\omega t) - \cos(\omega_0 t) = 2 \sin(\\frac{\omega + \omega_0}{2}t) \sin(\\frac{\omega - \omega_0}{2}t)$') | html(r'$\cos(\omega t) - \cos(\omega_0 t) = 2 \sin(\\frac{\omega + \omega_0}{2}t) \sin(\frac{\omega - \omega_0}{2}t)$') |
Line 35: | Line 35: |
s2str = ''.join(wave.struct.pack('h',x) for x in s2f) | s2str = b''.join(wave.struct.pack('f',x) for x in s2f) |
Line 41: | Line 41: |
html('<embed src="cell://test'+ lab +'.wav" width="200" height="100"></embed>') html('Frequencies: '+ '$\omega_0 = ' + str(hz1) + ' $, $\omega = '+latex(hz2) + '$') |
pretty_print(html(r'<embed src="cell://test'+ lab +'.wav" width="200" height="100"></embed>')) pretty_print(html(r'Frequencies: $\omega_0 = {} $, $\omega = {}$'.format(str(hz1),latex(hz2)))) |
Line 56: | Line 56: |
self.sr = 44100 | self.sr = int(44100) |
Line 90: | Line 90: |
html("Karplus-Strong algorithm with blending and delay stretching") html("<br>K. Karplus and A. Strong, <em>Digital synthesis of plucked string and drum timbres</em>, \nComputer Music Journal 7 (2) (1983), 43–55.<br>") html("Initial waveform:") |
pretty_print(html("Karplus-Strong algorithm with blending and delay stretching")) pretty_print(html("<br>K. Karplus and A. Strong, <em>Digital synthesis of plucked string and drum timbres</em>, \nComputer Music Journal 7 (2) (1983), 43–55.<br>")) pretty_print(html("Initial waveform:")) |
Line 94: | Line 94: |
html("Waveform after stabilization:") | pretty_print(html("Waveform after stabilization:")) |
Line 96: | Line 96: |
s2str = ''.join(wave.struct.pack('h',x) for x in s2f) | s2str = b''.join(wave.struct.pack('f',x) for x in s2f) |
Line 100: | Line 100: |
html('<embed src="cell://test'+ lab +'.wav" width="200" height="100"></embed>') | pretty_print(html('<embed src="cell://test'+ lab +'.wav" width="200" height="100"></embed>')) |
Line 122: | Line 122: |
html('<center>') html("$X \cap Y$ = %s"%f(XY)) html("$X \cap Z$ = %s"%f(XZ)) html("$Y \cap Z$ = %s"%f(YZ)) html("$X \cap Y \cap Z$ = %s"%f(XYZ)) html('</center>') |
pretty_print(html("<center><p>$X \\cap Y$ = {}</p><p> $X \\cap Z$ = {}</p><p> $Y \\cap Z$ = {}</p><p> $X \\cap Y \\cap Z$ = {}<center>".format(f(XY),f(XZ),f(YZ),f(XYZ)))) |
Line 166: | Line 161: |
print (lambda f:f(0,f))( | print((lambda f:f(0,f))( |
Line 171: | Line 166: |
) | )) |
Line 178: | Line 173: |
html('<h2>Profile the given input</h2>') | pretty_print(html('<h2>Profile the given input</h2>')) |
Line 198: | Line 193: |
print globals()[system].eval(code) | print(globals()[system].eval(code)) |
Line 207: | Line 202: |
def minkdemo(list1,list2): | def minkdemo(list1, list2): |
Line 209: | Line 204: |
Returns the Minkowski sum of two lists. | Return the Minkowski sum of two lists. |
Line 214: | Line 209: |
temp = [stuff1[i] + stuff2[i] for i in range(len(stuff1))] output.append(temp) |
output.append([a + b for a, b in zip(stuff1, stuff2)]) |
Line 217: | Line 211: |
@interact def minksumvis(x1tri = slider(-1,1,1/10,0, label = 'Triangle point x coord.'), yb = slider(1,4,1/10,2, label = 'Blue point y coord.')): t_list = [[1,0],[x1tri,1],[0,0]] |
@interact def minksumvis(x1tri=slider(-1,1,1/10,0, label='Triangle point x coord.'), yb=slider(1,4,1/10,2, label='Blue point y coord.')): t_list = [[1,0], [x1tri,1], [0,0]] |
Line 230: | Line 225: |
for an_edge in p12poly.vertex_adjacencies(): edge_lines += line([verts[an_edge[0]], verts[an_edge[1][0]]]) edge_lines += line([verts[an_edge[0]], verts[an_edge[1][1]]]) |
for v0, v1 in p12poly.graph().edges(False): edge_lines += line([v0, v1]) |
Line 269: | Line 263: |
M[0]=[randint(0,1) for a in range(0,2*N+2)] | M[0]=[randint(0,1) for a in range(2*N+2)] |
Line 272: | Line 266: |
for k in range(0,2*N): | for k in range(2*N): |
Line 300: | Line 294: |
# Adapted from http://wiki.sagemath.org/interact/misc # An_Interactive_Venn_Diagram # This interact models problems in which a certain number of people are surveyed to see if they participate in three different activities (running, biking, and swimming). Users can indicate the numbers of people, from 0 to 100. Returns a graphic of a labeled Venn diagram with the number of people in each region. Returns an explanatory error message if user input is inconsistent. |
|
Line 307: | Line 296: |
Line 317: | Line 306: |
Line 322: | Line 311: |
Line 330: | Line 319: |
Line 338: | Line 327: |
Line 341: | Line 330: |
Line 343: | Line 332: |
C=T-XX-YY-ZZ-ZX-ZY-YX-XYZ | C = T-XX-YY-ZZ-ZX-ZY-YX-XYZ |
Line 347: | Line 336: |
if XYZ>XY or XYZ>XZ or XYZ>YZ or XY>X or XY>Y or XZ>X or XZ>Z or YZ>Y or YZ>Z or C<0: print 'This situation is impossible!' if XYZ > XY: print 'The number of people who run, bike, and swim cannot be greater than the number of people who run and bike! (Why?)' if XYZ > XZ: print 'The number of people who run, bike, and swim cannot be greater than the number of people who run and swim! (Why?)' if XYZ > YZ: print 'The number of people who run, bike, and swim cannot be greater than the number of people who bike and swim! (Why?)' if XY > X: print 'The number of people who run and bike cannot be greater than the number of people who run! (Why?)' if XY > Y: print 'The number of people who run and bike cannot be greater than the number of people who bike! (Why?)' if XZ > X: print 'The number of people who run and swim cannot be greater than the number of people who run! (Why?)' if XZ > Z: print 'The number of people who run and swim cannot be greater than the number of people who swim! (Why?)' if YZ > Y: print 'The number of people who bike and swim cannot be greater than the number of people who bike! (Why?)' if YZ > Z: print 'The number of people who bike and swim cannot be greater than the number of people who swim! (Why?)' if C<0: print 'You have indicated too many people! The number of people exceeds the number of people surveyed. (Why?)' |
if XYZ>XY or XYZ>XZ or XYZ>YZ or XY>X or XY>Y or XZ>X or XZ>Z or YZ>Y or YZ>Z or C<0 or XYZ<0 or XZ<0 or YZ<0 or XY<0 or X<0 or Y<0 or Z<0 or XX<0 or YY<0 or ZZ<0: print('This situation is impossible! (Why?)') |
Line 372: | Line 341: |
{{attachment:vennjhl.png}} |
Sage Interactions - Miscellaneous
goto interact main page
Contents
Hearing a trigonometric identity
by Marshall Hampton. When the two frequencies are well separated, we hear the right hand side of the identity. When they start getting close, we hear the higher-pitched factor in the left-hand side modulated by the lower-pitched envelope.
Karplus-Strong algorithm for plucked and percussive sound generation
by Marshall Hampton
An Interactive Venn Diagram
Unreadable code
by Igor Tolkov
Profile a snippet of code
Evaluate a bit of code in a given system
by William Stein (there is no way yet to make the text box big):
Minkowski Sum
by Marshall Hampton
Cellular Automata
by Pablo Angulo, Eviatar Bach
Another Interactive Venn Diagram
by Jane Long (adapted from http://wiki.sagemath.org/interact/misc)
This interact models a problem in which a certain number of people are surveyed to see if they participate in three different activities (running, biking, and swimming). Users can indicate the numbers of people in each category, from 0 to 100. Returns a graphic of a labeled Venn diagram with the number of people in each region. Returns an explanatory error message if user input is inconsistent.