Python 3.2 Vectors.py module
Algis Kabaila
akabaila at pcug.org.au
Sun May 15 05:15:48 EDT 2011
Hi All,
I would really appreciate any comments and suggestions for the
Vectors.py module, which can be downloaded from
http://akabaila.pcug.org.au/linalg/vectors.tar.gz
The tar ball is only about 4 KiB, but I gather that this mailing
list does not tolerate attachments.
The module is designed with PYTHON 3.2 and it is required for
some structural analysis programs to port them to Python 3.x
world. A quick start introduction to the module follows
*********************************
#!/usr/bin/env python3.2
''' quickVector.py - quick introduction to Vectors module. More
information in "the manual". The quick introduction starts right
here! With Vectors.py in the current directory, fire up the
Python 3.2 Idle and try Vector algebra in the Python Shell.
(Alternatively, just fire up Python 3.2 and try the commands
from the terminal - CLI.
>>> from Vectors import Vector
>>> v1 = Vector(3, 4)
>>> print('v1 = ', v1)
v1 = Vector(3.0, 4.0, 0.0)
>>> print('v1.size =', v1.size)
v1.size = 5.0
>>> v2 = Vector(0, -5)
>>> print('v2 =', v2)
v2 = Vector(0.0, -5.0, 0.0)
>>> print('scalar product =', v1 * v2)
scalar product = -20.0
>>> print('vector product =', v1 ** v2)
vector product = Vector(0.0, 0.0, -15.0)
>>> v3 = v1 + v2
>>> print('v1 + v2 =', v3)
v1 + v2 = Vector(3.0, -1.0, 0.0)
>>> print('v3 - v1 verify = v2 =', v3 -v1)
v3 - v1 verify = v2 = Vector(0.0, -5.0, 0.0)
>>> # All vectors are three dimensional. But
>>> # by specifying z = 0 we had vectors in (x y)
>>> # plane. However, when we form a vector product
>>> # (aka cross product), the resulting vector has
>>> # to be at right angles to the (x y) plane, so
>>> # we return to the 3 Dimensional media...
>>> # Vector (cross) product is signalled by **
>>> w1 = v1 ** v2
>>> print('w1 = v1 ** v2 =', w1)
w1 = v1 ** v2 = Vector(0.0, 0.0, -15.0)
>>> w2 = w1 + v1
>>> print('w2 a vector in 3 dim. =', w2)
w2 a vector in 3 dim. = Vector(3.0, 4.0, -15.0)
>>> # Time to look at the "user manual" and other examples.
>>> # Temp. home: http://akabaila/pcug.org.au/linalg/vectors.py
'''
import doctest
doctest.testmod()
*********************************
Thank you in anticipation for suggestions and comments.
OldAl.
--
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110515/cad5f70b/attachment.html>
More information about the Python-list
mailing list