Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

How do I create and plot a vector from the difference between two points?

asked 10 years ago

nardaen gravatar image

updated 10 years ago

Having points a and b, how do I create a vector that goes from a to b? I'm trying the following but I get an error:

a=[(1,0,0)]
b=[(0,-1,0)]
u=vector(b-a)

Then, how do I plot a, b and u at the position of a? The error is

File "/tmp/tmpoTA_jw/___code___.py", line 6, in <module> exec compile(u'u=vector(b-a) File "", line 1, in <module> TypeError: unsupported operand type(s) for -: 'list' and 'list'

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 10 years ago

tmonteil gravatar image

When you write a=[(1,0,0)], a becomes the name of a list that contains a single element, which is the tuple (1,0,0), list and tuples are Python objects.

Note that tuples can be added, but since most Python programmers are not mathematicians, the most useful way to define addition is by concatenation:

sage: (1,0,0) + (3,4)
(1, 0, 0, 3, 4)
sage: (1,0,0) + ('a','b')
(1, 0, 0, 'a', 'b')

For tuples and lists, subtraction is not defined:

sage: (1,0,0) - (3,4,4)
TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'

So, it s better to define points in a vector space as vectors themselves, and the vector joining the two points is just their difference:

sage: a = vector((1,0,0))
sage: b = vector((0,-1,0))
sage: u = b-a
sage: u
(-1, -1, 0)
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 10 years ago

Seen: 2,151 times

Last updated: Mar 07 '15