Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: DEC
Views: 183

PyDEC: Adaptando para SageMath

%auto pyton2 = jupyter('python2') %default_mode pyton2 sage=jupyter('sagemath')
Error in lines 3-3 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_jupyter.py", line 32, in __call__ raise ValueError("You may not run Sage kernels from a Sage worksheet.\nInstead use the sage_select command in a Terminal to\nswitch to a different version of Sage, then restart your project.") ValueError: You may not run Sage kernels from a Sage worksheet. Instead use the sage_select command in a Terminal to switch to a different version of Sage, then restart your project.
#pacotes from numpy import array, transpose, dot # criar arrays, calcula a transposta de uma array, produto de matrizes from numpy.linalg import inv # calcula a matrix inversa from pydec import abstract_simplicial_complex,simplex_array, simplicial_complex, simplicial_mesh,d,cochain # d calcula o bordo e desta from pydec.vis.draw import triplot # plota malhas triângulares #from pydec.mesh import simplicial_mesh #from pydec.dec import simplicial_complex

Simples Triângulo

%sage v_0=vector([0,0]) v_1=vector([1,0]) v_2=vector([0,1]) cc=(v_0+v_1)/2 a = polygon2d([v_0,v_1,v_2], fill=False, axes=False) p=point([v_0,v_1,v_2,],size=30, color='red') v0=text('$0=(0,0)$',(-0.03,0), horizontal_alignment='right') v1=text('$v_1=(1,0)$',(1.03,0), horizontal_alignment='left') v2=text('$v_2=(0,1)$',(-0.03,1), horizontal_alignment='right') cc=text('$cc=(1/2,1/2)$',(0.53,0.5), horizontal_alignment='left') v0v1=arrow(v_0,(0.5,0), width=1, arrowsize=2) v1v2=arrow(v_1,(1/2,1/2), width=1, arrowsize=2) v0v2=arrow(v_0,(0,1/2), width=1, arrowsize=2) T=a+p+v0+v1+v2+v0v1+v1v2+v0v2 show(T, figsize=[2,2])
Vt = [[0,0],[1,0],[0.5,1]] # spatial coordinates St = [[0,1,2]] # indicies vertices sct=simplicial_complex((Vt,St)) boundary_triangulo0=sct[0].d #vertice boundary operator boundary_triangulo1=sct[1].d # edges boundary operator d0=boundary_triangulo0.toarray() # transforma matrix sparsa em array d1=boundary_triangulo1.toarray() # transforma matrix sparsa em array h0=sct[0].star # Hodge Star Operador act 0-form h1=sct[1].star print d0, '\n\n' print d1, '\n\n' print h0.toarray(), '\n\n' print h1.toarray(), '\n\n' print reduce(dot,[-inv(h0),d0.T triplot(Vt, St)
[[-1 1 0] [-1 0 1] [ 0 -1 1]] [[ 1 -1 1]] [[ 0.171875 0. 0. ] [ 0. 0.171875 0. ] [ 0. 0. 0.15625 ]] [[ 0.375 0. 0. ] [ 0. 0.25 0. ] [ 0. 0. 0.25 ]]
hodget0=sct[0].star # Hodge Star Operador act 0-form hodget1=sct[1].star # Hodge Star Operador act 1-form ht0=hodget0.toarray() ht1=hodget1.toarray() print 'ht0','=',ht0, '\n\n' print 'ht1','=',ht1
ht0 = [[ 0.194125 0. 0. ] [ 0. 0.154625 0. ] [ 0. 0. 0.15125 ]] ht1 = [[ 0.395 0. 0. ] [ 0. 0.35 0. ] [ 0. 0. 0.15 ]]
sct=compute_circumcenters
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-25-588a565cbb99> in <module>()
----> 1 sct=compute_circumcenters

NameError: name 'compute_circumcenters' is not defined
coderivative1=dot(dot(-inv(ht0),transpose(bt0)),ht1) #coderivative print coderivative1
[[ 2.03477141 1.80296201 0. ] [-2.5545675 0. 0.97008892] [ 0. -2.31404959 -0.99173554]]

Malha Triângular

V=[[0,0],[1,0],[2,0],[1,1],[2,1]] # coordenadas espaciais dos vertices S_0=[[0],[1],[2],[3],[4]] # vertices (0 simplex) S_1=[[0,1],[0,3],[1,2],[1,3],[2,3],[2,4],[3,4]] #arestas(1-simplex) S_2=[[0,1,3],[1,2,3],[2,4,3]] # triângulo (2-simplex)
sc=simplicial_complex((V,S_2)) #object simplicial complex boundary0=sc[0].d #vertice boundary operator boundary1=sc[1].d #edges boundary operator b0=boundary0.toarray() b1=boundary1.toarray() boundarymesh=sc.boundary() print boundarymesh, '\n' print 'b0','=',b0,'\n\n' print 'b1','=',b1, '\n\n' #print simplex_array.simplex_array_boundary(array(S_2), array([0,1,2]))[1].toarray()
[simplex((0, 1),parity=0), simplex((1, 2),parity=0), simplex((0, 3),parity=0), simplex((3, 4),parity=0), simplex((2, 4),parity=0)] b0 = [[-1 1 0 0 0] [-1 0 0 1 0] [ 0 -1 1 0 0] [ 0 -1 0 1 0] [ 0 0 -1 1 0] [ 0 0 -1 0 1] [ 0 0 0 -1 1]] b1 = [[ 1 -1 0 1 0 0 0] [ 0 0 1 -1 1 0 0] [ 0 0 0 0 -1 1 -1]]
hodge0=sc[0].star # Hodge Star Operador 0-simplex hodge1=sc[1].star # Hodge Star Operador 1-simplex h0=hodge0.toarray() h1=hodge1.toarray() print 'h0','=',h0, '\n\n' print 'h1','=',h1, '\n\n'
h0 = [[ 0.125 0. 0. 0. 0. ] [ 0. 0.5 0. 0. 0. ] [ 0. 0. 0.25 0. 0. ] [ 0. 0. 0. 0.375 0. ] [ 0. 0. 0. 0. 0.25 ]] h1 = [[ 0.5 0. 0. 0. 0. 0. 0. ] [ 0. 0. 0. 0. 0. 0. 0. ] [ 0. 0. 0.5 0. 0. 0. 0. ] [ 0. 0. 0. 1. 0. 0. 0. ] [ 0. 0. 0. 0. 0. 0. 0. ] [ 0. 0. 0. 0. 0. 0.5 0. ] [ 0. 0. 0. 0. 0. 0. 0.5]]
pydec/dec/simplicial_complex.py:175: RuntimeWarning: divide by zero encountered in divide data.star_inv = sparse.spdiags([1.0/stardiag],[0], N, N, format='csr')
coderivative1=dot(dot(-inv(h0),transpose(b0)),h1) #coderivative print coderivative1
[[ 4. 0. 0. 0. 0. 0. 0. ] [-1. 0. 1. 2. 0. 0. 0. ] [ 0. 0. -2. 0. 0. 2. 0. ] [ 0. 0. 0. -2.66666667 0. 0. 1.33333333] [ 0. 0. 0. 0. 0. -2. -2. ]]

Complex abstrato: Faixa de Mobius Discreta

M=array([[0,1,3],[0,3,5], [3,2,5],[5,2,4],[2,0,4],[0,1,4]]) # manifold(Faixa de Mobius Discreta) abst_cplx=abstract_simplicial_complex(M)
Vth= [[2,1,-1], [3,0,1], [2,-1,3], [0,-7,0]] # spatial coordinates Sth= [[0,1,2,3]] # indicies vertices sct=simplicial_complex((Vth,Sth)) print sct
simplicial_complex: complex: 1: 3-simplices 4: 2-simplices 6: 1-simplices 4: 0-simplices
print sct[0].d.toarray()
[[-1 1 0 0] [-1 0 1 0] [-1 0 0 1] [ 0 -1 1 0] [ 0 -1 0 1] [ 0 0 -1 1]]
print sct[0].star.toarray()
[[ 6.40722222 0. 0. 0. ] [ 0. 7.08793924 0. 0. ] [ 0. 0. 9.8506705 0. ] [ 0. 0. 0. 4.94002463]]
Vth2=[[1,1,1], [1,-1,-1], [-1,1,-1], [-1,-1,1]] Sth2=[[0,1,2,3]] sct2=simplicial_complex((Vth,Sth))
Error in lines 3-3 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1009, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'simplicial_complex' is not defined
print sct2[1].d.toarray()
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1009, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'sct2' is not defined
print sct2[0].d.toarray()
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1009, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'sct2' is not defined
print sct2[0].star.toarray()
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1009, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'sct2' is not defined
D0=sct[0].d H1=sct[1].star B=sct2.boundary() L=array(dot(D0.T.todense(),dot(H1.todense(),D0.todense()))) print B
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1009, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'sct' is not defined
+print L
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1009, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "<string>", line 1 +print L ^ SyntaxError: invalid syntax
from scipy.linalg import eig, solve,lstsq,inv, det, norm solve(L,array([0,0,0,0]))
Error in lines 2-2 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1009, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'L' is not defined