Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 5216
# Lab 1: Plotting legs of PPTs (template) reset
<function reset at 0x7f539f74f050>
#Part 1: making list of lists [m,n] from fractions without duplicates #Input: N, the number of diagonals in the table given in the lab description #Output:list of fractions m/n on the N diagonals without duplicates. def mn_list(N): S=[]# This list will store fractions m/n from the table L=[] # This list wil store lists [m,n] for n in range(2,N+2): temp=[QQ(m)/QQ(n) for m in range(1,n)]# List comprehension constructor is used here S.extend(temp)# Learn about command extend and use it here S=list(set(S))# This command excludes duplication for c in S: mn=[numerator(c),denominator(c)]# Make a list [m,n] from the fraction m/n L.append(temp) return L
def mn_pairs(N): L=[]; for n in range(2,N+2): temp=[[m,n] for m in range (1,n)] L.extend(temp) return L
L=mn_pairs(8);L
[[1, 2], [1, 3], [2, 3], [1, 4], [2, 4], [3, 4], [1, 5], [2, 5], [3, 5], [4, 5], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [1, 7], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [1, 8], [2, 8], [3, 8], [4, 8], [5, 8], [6, 8], [7, 8], [1, 9], [2, 9], [3, 9], [4, 9], [5, 9], [6, 9], [7, 9], [8, 9]]
#Part 2: PPT list #Input: List L of lists [m,n] #Output: List of ppt_legs of legs [a,b] of PPTs constructed from [m,n] in L according to version 2 of the characterization theorem for PPTs
[]
Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_parsing.py", line 533, in introspect obj if not preparse else preparse_code(obj), namespace) File "<string>", line 1, in <module> NameError: name 'my_ppt_list' is not defined
#Part 3: Plotting legs of PPTs using data in ppt_legs list #Learn about the syntax of command list_plot and use the command for this task import matplotlib.pyplot as plt from matplotlib.pyplot import figure
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1188, in execute flags=compile_flags), namespace, locals) File "", line 1, in <module> File "", line 3, in ppt_legs TypeError: 'list' object is not callable
def plot_ppt(ppt_legs): x=[c[0] for c in ppt_legs] y=[c[1] for c in ppt_legs] figure(num=None, figsize=(5, 3)) figure=plt.plot(x, y,'ro',xblue,yblue,'bo',markersize=4) plt.show(figure)
#Advanced nice snippet of code for plotting (just FYI) import numpy as np import matplotlib.pyplot as plt #evenly sampled time at 200ms intervals t = np.arange(0., 5., 0.2) # red dashes, blue squares and green triangles plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') plt.show()
# Lab 1: Plotting legs of PPTs (template) reset
<function reset at 0x7f539f74f050>
#Part 1: making list of lists [m,n] from fractions without duplicates #Input: N, the number of diagonals in the table given in the lab description #Output:list of fractions m/n on the N diagonals without duplicates. def mn_list(N): S=[]# This list will store fractions m/n from the table L=[] # This list wil store lists [m,n] for n in range(2,N): temp=[QQ(m)/QQ(n) for m in range(1,n)]# List comprehension constructor is used here S.extend(temp)# Learn about command extend and use it here S=list(set(S))# This command excludes duplication for c in S: mn=[numerator(c),denominator(c)]# Make a list [m,n] from the fraction m/n L.append(temp) return L
testplot=mn_list(10);testplot
[[1, 2], [1, 3], [2, 3], [1, 4], [3, 4], [1, 5], [2, 5], [3, 5], [4, 5], [1, 6], [5, 6], [1, 7], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [3, 8], [5, 8], [1, 9], [7, 8], [4, 9], [5, 9], [7, 9], [8, 9], [1, 8], [2, 9]]
#Part 2: PPT list #Input: List L of lists [m,n] #Output: List of ppt_legs of legs [a,b] of PPTs constructed from [m,n] in L according to version 2 of the characterization theorem for PPTs ...
#Part 3: Plotting legs of PPTs using data in ppt_legs list #Learn about the syntax of command list_plot and use the command for this task import matplotlib.pyplot as plt from matplotlib.pyplot import figure
def plot_ppt(ppt_legs): x=[c[0] for c in ppt_legs] y=[c[1] for c in ppt_legs] figure(num=None, figsize=(5, 3)) figure=plt.plot(x, y,'ro',xblue,yblue,'bo',markersize=4) plt.show(figure)
#Advanced nice snippet of code for plotting (just FYI) import numpy as np import matplotlib.pyplot as plt #evenly sampled time at 200ms intervals t = np.arange(0., 5., 0.2) # red dashes, blue squares and green triangles plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') plt.show()