Ask Your Question

ameetnsharma's profile - activity

2019-06-15 09:10:36 -0600 received badge  Famous Question (source)
2019-01-03 02:17:24 -0600 received badge  Famous Question (source)
2018-07-03 09:56:09 -0600 received badge  Notable Question (source)
2017-06-24 07:41:19 -0600 received badge  Notable Question (source)
2017-06-14 14:32:42 -0600 received badge  Popular Question (source)
2017-01-03 19:48:32 -0600 received badge  Notable Question (source)
2017-01-03 19:48:26 -0600 received badge  Popular Question (source)
2016-05-25 22:45:37 -0600 asked a question Getting convex hull of a set of points and plotting the polygon

I'm using sagemath cloud.

I'm trying to get the convex hull of a finite set of points, then plotting the polygon. If I just plot the polygon with the vertices directly, I don't get the vertices in the right order to make up a convex polygon (plots edges joining the wrong points). Then I found out about cyclic_sort_vertices_2d which I thought would sort the vertices into the right order, but that's giving me errors. I don't understand the meaning of the errors. Appreciate any help.

here's the relevant code:

hull = Polyhedron(vertices=thePoints);
hull.vertices();
cyclic_sort_vertices_2d(hull.vertices());

And I have this import line at the top of my code for cyclic sort:

from sage.geometry.polyhedron.plot import cyclic_sort_vertices_2d;

Here's my output:

 (A vertex at (9464.0, 10816.0), A vertex at (8736.0, 7735.0), A vertex at (7904.0, 8736.0), A vertex at (11088.0, 5607.0), A vertex at (15552.0, 6480.0), A vertex at (8160.0, 9248.0), A vertex at (8568.0, 9792.0), A vertex at (11076.0, 10140.0), A vertex at (12852.0, 5355.0))

And errors:

Error in lines 28-30
Traceback (most recent call last):
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/plot.py", line 245, in cyclic_sort_vertices_2d
    adjacency_matrix = Vlist[0].polyhedron().vertex_adjacency_matrix()
  File "sage/misc/cachefunc.pyx", line 2215, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (/projects/sage/sage-6.10/src/build/cythonized/sage/misc/cachefunc.c:14346)
    self.cache = f(self._instance)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 1847, in vertex_adjacency_matrix
    return self._vertex_adjacency_matrix()
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 312, in _vertex_adjacency_matrix
    face_lattice = self.face_lattice()
  File "sage/misc/cachefunc.pyx", line 2215, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (/projects/sage/sage-6.10/src/build/cythonized/sage/misc/cachefunc.c:14346)
    self.cache = f(self._instance)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base.py", line 3172, in face_lattice
    face_constructor=face_constructor, required_atoms=atoms_vertices)
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/sage/geometry/hasse_diagram.py", line 182, in Hasse_diagram_from_incidences
    for coatom, atoms in enumerate(coatom_to_atoms)]
KeyError: (frozenset([]), frozenset([0]))
2016-05-25 22:32:20 -0600 received badge  Popular Question (source)
2015-11-07 22:03:54 -0600 received badge  Student (source)
2015-11-07 18:56:35 -0600 commented answer solving simultaneous equations

Thanks! I see now.

2015-11-07 12:21:00 -0600 asked a question solving simultaneous equations

Here's my code:

x1, y1, x2, y2 = var('x1 y1 x2 y2')
eq1 = (x1-1)*(x1-2) + (y1-3)*(y1-4) == 0
eq2 = (x2-1)*(x2-2) + (y2-3)*(y2-4) == 0
eq3 = x1+x2 == 3
eq4 = y1+y2 == 7
sols = solve([eq1,eq2,eq3,eq4],x1,y1,x2,y2,solution_dict=True)
for soln in sols:
    for varbl in soln:
        print "{0} : {1},".format(varbl, soln[varbl])

And here's my output:

x1 + x2 : 3,
(x1 - 1)*(x1 - 2) + (y1 - 3)*(y1 - 4) : 0,
(x2 - 1)*(x2 - 2) + (y2 - 3)*(y2 - 4) : 0,
y1 + y2 : 7,

I'm looking for any solutions, exact or numerical approximation. Appreciate any help. I can solve the problem by hand, but obviously that's not the point here. I'm trying to find out what I'm doing wrong and learn to use sagemath cloud properly.

2015-11-07 12:13:48 -0600 received badge  Scholar (source)
2015-11-07 12:13:45 -0600 commented answer Having trouble solving simultaneous questions

It is not letting me upvote. I will accept the answer though.

2015-11-07 10:07:58 -0600 commented answer Having trouble solving simultaneous questions

Seems like replacing x with x1 helped a little, but it's not solving the system of equations.

2015-11-07 10:06:11 -0600 commented answer Having trouble solving simultaneous questions

Thanks. I tried that and here's what I get: x1, y1, x2, y2 = var('x1 y1 x2 y2')

eq1 = (x1-1)(x1-2) + (y1-3)(y1-4) == 0 eq2 = (x2-1)(x2-2) + (y2-3)(y2-4) == 0 eq3 = x1+x2 == 3 eq4 = y1+y2 == 7 sols = solve([eq1,eq2,eq3,eq4],x1,y1,x2,y2,solution_dict=True)

for soln in sols: for varbl in soln: print "{0} : {1},".format(varbl, soln[varbl])

HEre's the output:

x1 + x2 : 3, (x1 - 1)(x1 - 2) + (y1 - 3)(y1 - 4) : 0, (x2 - 1)(x2 - 2) + (y2 - 3)(y2 - 4) : 0, y1 + y2 : 7,

2015-11-07 07:25:12 -0600 received badge  Editor (source)
2015-11-07 07:19:22 -0600 asked a question Having trouble solving simultaneous questions

I'm trying to use sagemath cloud to solve simultaneous equations, but I'm having trouble. Can you please look at the code below and see what I'm doing wrong. sagemath cloud gives the following error:

Error in lines 7-7 Traceback (most recent call last): File "/projects/sage/sage-6.9/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> KeyError: x

My code:

x, y, x2, y2 = var('x y x2 y2')

eq1 = (x-1)(x-2) + (y-3)(y-4) == 0

eq2 = (x2-1)(x2-2) + (y2-3)(y2-4) == 0

eq3 = x+x2 == 3

eq4 = y+y2 == 7

sols = solve([eq1,eq2,eq3,eq4],x,y,x2,y2,solution_dict=True)

for soln in sols: print "x: %s, y: %s x2: %s y2: %s"%(soln[x], soln[y],soln[x2],soln[y2])