9831
Comment:
|
12910
|
Deletions are marked like this. | Additions are marked like this. |
Line 8: | Line 8: |
by Marshall Hampton. When the two frequencies are well seperated, 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. {{{ |
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. {{{#!sagecell |
Line 28: | Line 28: |
def sinsound(freq_ratio = slider(0,1,1/144,1/12)): | def sinsound(freq_ratio = slider(1/144,1,1/144,1/12)): |
Line 41: | Line 41: |
html('<embed src="https:./test'+ lab +'.wav" width="200" height="100"></embed>') | html('<embed src="cell://test'+ lab +'.wav" width="200" height="100"></embed>') |
Line 49: | Line 49: |
{{{ | {{{#!sagecell |
Line 100: | Line 100: |
html('<embed src="https:./test'+ lab +'.wav" width="200" height="100"></embed>') | html('<embed src="cell://test'+ lab +'.wav" width="200" height="100"></embed>') |
Line 107: | Line 107: |
{{{ | {{{#!sagecell |
Line 163: | Line 163: |
{{{ | {{{#!sagecell |
Line 177: | Line 177: |
{{{ | {{{#!sagecell |
Line 184: | Line 184: |
print "<html>" # trick to avoid word wrap | |
Line 186: | Line 185: |
cProfile.run(cmd) | cProfile.runctx(cmd,globals(), locals()) |
Line 188: | Line 187: |
profile.run(cmd) print "</html>" |
profile.runctx(cmd,globals(), locals()) |
Line 197: | Line 195: |
{{{ | {{{#!sagecell |
Line 200: | Line 198: |
print globals()[system].eval(code) | print(globals()[system].eval(code)) |
Line 208: | Line 206: |
{{{ def minkdemo(list1,list2): |
{{{#!sagecell def minkdemo(list1, list2): |
Line 211: | Line 209: |
Returns the Minkowski sum of two lists. | Return the Minkowski sum of two lists. |
Line 216: | Line 214: |
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 219: | Line 216: |
@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 232: | Line 230: |
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 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]]]) |
Line 256: | Line 254: |
{{{ | {{{#!sagecell |
Line 258: | Line 256: |
def cellular(rule, N): |
from random import randint def cellular(rule, N, initial='Single-cell'): |
Line 264: | Line 263: |
initial: starting condition; can be either single-cell or a random binary row | |
Line 266: | Line 266: |
M[0,N]=1 | if initial=='Single-cell': M[0,N]=1 else: M[0]=[randint(0,1) for a in range(0,2*N+2)] |
Line 273: | Line 276: |
}}} {{{ |
|
Line 282: | Line 284: |
def _( N=input_box(label='Number of iterations',default=100), | def _( initial=selector(['Single-cell', 'Random'], label='Starting condition'), N=input_box(label='Number of iterations',default=100), |
Line 284: | Line 286: |
size = slider(1, 11, step_size=1, default=6 ) ): | size = slider(1, 11, label= 'Size', step_size=1, default=6 ), auto_update=False): |
Line 286: | Line 288: |
M = cellular(rule, N) | M = cellular(rule, N, initial) |
Line 291: | Line 293: |
== 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. {{{#!sagecell @interact def _(T=slider([0..100],default=100,label='People surveyed'),X=slider([0..100],default=28,label='Run'), Y=slider([0..100],default=33,label='Bike'), Z=slider([0..100],default=59,label='Swim'),XY=slider([0..100],default=16,label='Run and Bike'),XZ=slider([0..100],default=13,label='Run and Swim'),YZ=slider([0..100],default=12,label='Bike and Swim'),XYZ=slider([0..100],default=7,label='Run, Bike, and Swim')): centers = [(cos(n*2*pi/3), sin(n*2*pi/3)) for n in [0,1,2]] scale = 1.7 clr = ['yellow', 'blue', 'green'] G = Graphics() for i in range(3): G += circle(centers[i], scale, rgbcolor=clr[i], fill=True, alpha=0.3) for i in range(3): G += circle(centers[i], scale, rgbcolor='black') # Label sets G += text('Run',(3,0),rgbcolor='black') G += text('Bike',(-1,3),rgbcolor='black') G += text('Swim',(-1,-3),rgbcolor='black') # Plot pairs of intersections ZX=XZ-XYZ G += text(ZX, (1.3*cos(2*2*pi/3 + pi/3), 1.3*sin(2*2*pi/3 + pi/3)), rgbcolor='black') YX=XY-XYZ G += text(YX, (1.3*cos(0*2*pi/3 + pi/3), 1.3*sin(0*2*pi/3 + pi/3)), rgbcolor='black') ZY=YZ-XYZ G += text(ZY, (1.3*cos(1*2*pi/3 + pi/3), 1.3*sin(1*2*pi/3 + pi/3)), rgbcolor='black') # Plot what is in one but neither other XX=X-ZX-YX-XYZ G += text(XX, (1.5*centers[0][0],1.7*centers[0][1]), rgbcolor='black') YY=Y-ZY-YX-XYZ G += text(YY, (1.5*centers[1][0],1.7*centers[1][1]), rgbcolor='black') ZZ=Z-ZY-ZX-XYZ G += text(ZZ, (1.5*centers[2][0],1.7*centers[2][1]), rgbcolor='black') # Plot intersection of all three G += text(XYZ, (0,0), rgbcolor='black') # Indicate number not in X, in Y, or in Z C = T-XX-YY-ZZ-ZX-ZY-YX-XYZ G += text(C,(3,-3),rgbcolor='black') # Check reasonableness before displaying result 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: print('This situation is impossible! (Why?)') else: G.show(aspect_ratio=1, axes=False) }}} {{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.