I want to compute the intersection of a plane r spanned by two vectors and another plane s defined by its implicit equation. I thought the following would work:

var('x0,x1,x2')
r0 = vector(QQ,[3,1,-2])
r1 = vector(QQ,[1,-5,3])
r = span([r0,r1])
s = 2*x0 - 3*x1 - 4*x2 == 0
r.annihilator([vector([2,-3,-4])])


But instead I am greeted with an error message saying that AttributeError: 'sage.rings.rational.Rational' object has no attribute '_vector_'.

What am I doing wrong?

edit retag close merge delete

Sort by » oldest newest most voted

r is correctly defined. For s, i would just do:

sage: s = matrix(QQ,[2,-3,-4]).right_kernel()
sage: s
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[   1    0  1/2]
[   0    1 -3/4]


Then you can do:

sage: s.intersection(r)
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[    1    15 -43/4]


And check

sage: r.intersection(s)
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[    1    15 -43/4]

sage: b = r.intersection(s).basis()[0] ; b
(1, 15, -43/4)
sage: b in r
True
sage: b in s
True


As a general rule, unlike say complex analysis, Sage already offers precise objects to work with linear spaces, polynomials, combinatorics, so that you should avoid the use of fuzzy symbolic things.

more

If you use the syntax in r.annihilator? then it makes it one step further:

sage: r.annihilator([2,-3,-4])
...
AttributeError: 'FreeModule_submodule_field_with_category' object has no attribute 'from_vector'


But I think you meant one vector, not three rationals, so that isn't helpful. I have opened Trac 21742 for this; I suspect this simply isn't a case where this was intended to be used.

more

My intention was to filter the elements of r such that they satisfied s's equation. That is, the elements of r which map to 0 when you do the dot vector with [2,-3,-4]. What would be the canonical way of doing this?

( 2016-10-22 13:47:44 -0600 )edit