Re: [sage-support] Re: How to calculate the affine coordinats of a point
that sounds comprehensibly. explains some more errormessages i got a few times (like 'bool has no attribute len' when using solve) greatz Am 18.07.2011 16:54, schrieb luisfe: For me it looks like: In solve, when writting a == b you assume that a and b are expressions involving several variables. If a and b are expressions, then a == b is also an expression. However, p and x*p1+y*p2 are NOT expressions, but vectors. And equality of vectors is not the same as equality of expressions sage: x == y x == y sage: type(_) type 'sage.symbolic.expression.Expression' sage: vector([x]) == vector([y]) False sage: type(_) type 'bool' So, in fact, you are passing the following command: sage: [x * p1 + y * p2 == p] [False] sage: solve([False],x,y) Which has no solution. It is subtle, but I would not consider it a bug. If you really want to use solve, you may try the following: sage: solve(x * p1 + y * p2 - p,x,y) [[x == (1/4), y == (3/4)]] In this case, the input is a vector, that is an iterable, so solve extracts its components and equals them to zero. Being said that, I recommend you to use the linear algebra interpretation that I suggested, since it will probably be much more efficient. -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: How to calculate the affine coordinats of a point
On Jul 16, 1:33 am, Johannes dajo.m...@web.de wrote: a very easy example would be this: sage: p1 = vector([-3,1,1]) sage: p2 = vector([1,-3,1]) sage: p = vector([0,-2,1]) #now i'm looking for some x,y such that #x * p1 + y * p1 == p x,y = var('x,y') sage: assume(x 0) sage: assume(y 0) sage: solve([x * p1 + y * p2 == p],x,y) [] #but: x = 1/4 and y = 3/4 is a solution of this equation. in the end i need this kind of calculation for every latticepoint on the border of a lattice-simplex. like the example above shows how it should work for a line, it also should be extendable to n+1 points on each n dimensional facet of the simplex, where the points p0,,pn are given as the vertices of the facet. greatz Johannes This is a linear algebra problem. You have a vector p that is a linear combinations of others p1,p2 and you want the coordinates of p in terms of B. This is only a change of basis problem. Assuming that the points of B form a basis of the linear span of B you can do: sage: m = matrix([p1,p2]) sage: m.solve_left(p) (1/4, 3/4) The rows of m are the vectors p1 and p2. You want to express p as combination of these rows. -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: How to calculate the affine coordinats of a point
thnx. I see that the problem can be also formulated as marix problem. but the way i did it is in this case the more natural one for me. is there any reason why it only works this way and solve does not lead to any result? greatz Johannes On 18 Jul., 14:45, luisfe lftab...@yahoo.es wrote: On Jul 16, 1:33 am, Johannes dajo.m...@web.de wrote: a very easy example would be this: sage: p1 = vector([-3,1,1]) sage: p2 = vector([1,-3,1]) sage: p = vector([0,-2,1]) #now i'm looking for some x,y such that #x * p1 + y * p1 == p x,y = var('x,y') sage: assume(x 0) sage: assume(y 0) sage: solve([x * p1 + y * p2 == p],x,y) [] #but: x = 1/4 and y = 3/4 is a solution of this equation. in the end i need this kind of calculation for every latticepoint on the border of a lattice-simplex. like the example above shows how it should work for a line, it also should be extendable to n+1 points on each n dimensional facet of the simplex, where the points p0,,pn are given as the vertices of the facet. greatz Johannes This is a linear algebra problem. You have a vector p that is a linear combinations of others p1,p2 and you want the coordinates of p in terms of B. This is only a change of basis problem. Assuming that the points of B form a basis of the linear span of B you can do: sage: m = matrix([p1,p2]) sage: m.solve_left(p) (1/4, 3/4) The rows of m are the vectors p1 and p2. You want to express p as combination of these rows. -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: How to calculate the affine coordinats of a point
On Jul 18, 3:48 pm, Johhannes dajo.m...@web.de wrote: thnx. I see that the problem can be also formulated as marix problem. but the way i did it is in this case the more natural one for me. is there any reason why it only works this way and solve does not lead to any result? For me it looks like: In solve, when writting a == b you assume that a and b are expressions involving several variables. If a and b are expressions, then a == b is also an expression. However, p and x*p1+y*p2 are NOT expressions, but vectors. And equality of vectors is not the same as equality of expressions sage: x == y x == y sage: type(_) type 'sage.symbolic.expression.Expression' sage: vector([x]) == vector([y]) False sage: type(_) type 'bool' So, in fact, you are passing the following command: sage: [x * p1 + y * p2 == p] [False] sage: solve([False],x,y) Which has no solution. It is subtle, but I would not consider it a bug. If you really want to use solve, you may try the following: sage: solve(x * p1 + y * p2 - p,x,y) [[x == (1/4), y == (3/4)]] In this case, the input is a vector, that is an iterable, so solve extracts its components and equals them to zero. Being said that, I recommend you to use the linear algebra interpretation that I suggested, since it will probably be much more efficient. -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org