def test_orthogonalize(): C = CoordSysCartesian('C') a, b = symbols('a b', integer=True); i, j, k = C.base_vectors() v1 = i + 2*j v2 = 2*i + 3*j v3 = 3*i + 5*j v4 = 3*i + j v5 = 2*i + 2*j v6 = a*i + b*j v7 = 4*a*i + 4*b*j assert orthogonalize(v1, v2) == [C.i + 2*C.j, 2*C.i/5 + -C.j/5] # from wikipedia assert orthogonalize(v4, v5, orthonormal=True) == \ [(3*sqrt(10))*C.i/10 + (sqrt(10))*C.j/10, (-sqrt(10))*C.i/10 + (3*sqrt(10))*C.j/10] raises(ValueError, lambda: orthogonalize(v1, v2, v3)) raises(ValueError, lambda: orthogonalize(v6, v7))
def test_orthogonalize(): C = CoordSysCartesian('C') a, b = symbols('a b', integer=True) i, j, k = C.base_vectors() v1 = i + 2*j v2 = 2*i + 3*j v3 = 3*i + 5*j v4 = 3*i + j v5 = 2*i + 2*j v6 = a*i + b*j v7 = 4*a*i + 4*b*j assert orthogonalize(v1, v2) == [C.i + 2*C.j, 2*C.i/5 + -C.j/5] # from wikipedia assert orthogonalize(v4, v5, orthonormal=True) == \ [(3*sqrt(10))*C.i/10 + (sqrt(10))*C.j/10, (-sqrt(10))*C.i/10 + (3*sqrt(10))*C.j/10] raises(ValueError, lambda: orthogonalize(v1, v2, v3)) raises(ValueError, lambda: orthogonalize(v6, v7))
from sympy.simplify import simplify, trigsimp from sympy import pi, sqrt, symbols, ImmutableMatrix as Matrix, sin, cos from sympy.vector.vector import Vector, BaseVector, VectorAdd, VectorMul, VectorZero from sympy.vector.coordsysrect import CoordSysCartesian C = CoordSysCartesian("C") i, j, k = C.base_vectors() a, b, c = symbols("a b c") def test_vector_sympy(): """ Test whether the Vector framework confirms to the hashing and equality testing properties of SymPy. """ i1 = BaseVector("i1", 0, C) assert i1 == i assert i1.__hash__() == i.__hash__() v1 = 3 * j assert v1 == j * 3 assert v1.components == {j: 3} v2 = 3 * i + 4 * j + 5 * k v3 = 2 * i + 4 * j + i + 4 * k + k assert v3 == v2 assert v3.__hash__() == v2.__hash__() def test_vector(): assert isinstance(i, BaseVector) assert i != j
from sympy.simplify import simplify, trigsimp from sympy import pi, sqrt, symbols, ImmutableMatrix as Matrix, \ sin, cos, Function, Integral, Derivative, diff, integrate from sympy.vector.vector import Vector, BaseVector, VectorAdd, \ VectorMul, VectorZero from sympy.vector.coordsysrect import CoordSysCartesian C = CoordSysCartesian('C') i, j, k = C.base_vectors() a, b, c = symbols('a b c') def test_vector_sympy(): """ Test whether the Vector framework confirms to the hashing and equality testing properties of SymPy. """ v1 = 3 * j assert v1 == j * 3 assert v1.components == {j: 3} v2 = 3 * i + 4 * j + 5 * k v3 = 2 * i + 4 * j + i + 4 * k + k assert v3 == v2 assert v3.__hash__() == v2.__hash__() def test_vector(): assert isinstance(i, BaseVector) assert i != j assert j != k