Ejemplo n.º 1
0
def test_gradient():
    a = Symbol('a')
    assert gradient(0, R) == Vector(0)
    assert gradient(R[0], R) == R.x
    assert gradient(R[0]*R[1]*R[2], R) == \
           R[1]*R[2]*R.x + R[0]*R[2]*R.y + R[0]*R[1]*R.z
    assert gradient(2*R[0]**2, R) == 4*R[0]*R.x
    assert gradient(a*sin(R[1])/R[0], R) == \
           - a*sin(R[1])/R[0]**2*R.x + a*cos(R[1])/R[0]*R.y
    assert gradient(P[0]*P[1], R) == \
           (-R[0]*sin(2*q) + R[1]*cos(2*q))*R.x + \
           (R[0]*cos(2*q) + R[1]*sin(2*q))*R.y
    assert gradient(P[0]*R[2], P) == P[2]*P.x + P[0]*P.z
Ejemplo n.º 2
0
def test_gradient():
    a = Symbol('a')
    assert gradient(0, R) == Vector(0)
    assert gradient(R[0], R) == R.x
    assert gradient(R[0]*R[1]*R[2], R) == \
           R[1]*R[2]*R.x + R[0]*R[2]*R.y + R[0]*R[1]*R.z
    assert gradient(2*R[0]**2, R) == 4*R[0]*R.x
    assert gradient(a*sin(R[1])/R[0], R) == \
           - a*sin(R[1])/R[0]**2*R.x + a*cos(R[1])/R[0]*R.y
    assert gradient(P[0]*P[1], R) == \
           (-R[0]*sin(2*q) + R[1]*cos(2*q))*R.x + \
           (R[0]*cos(2*q) + R[1]*sin(2*q))*R.y
    assert gradient(P[0]*R[2], P) == P[2]*P.x + P[0]*P.z
Ejemplo n.º 3
0
def test_gradient():
    a = Symbol("a")
    assert gradient(0, R) == Vector(0)
    assert gradient(R[0], R) == R.x
    assert (gradient(R[0] * R[1] * R[2], R) == R[1] * R[2] * R.x +
            R[0] * R[2] * R.y + R[0] * R[1] * R.z)
    assert gradient(2 * R[0]**2, R) == 4 * R[0] * R.x
    assert (gradient(a * sin(R[1]) / R[0],
                     R) == -a * sin(R[1]) / R[0]**2 * R.x +
            a * cos(R[1]) / R[0] * R.y)
    assert (gradient(P[0] * P[1],
                     R) == ((-R[0] * sin(q) + R[1] * cos(q)) * cos(q) -
                            (R[0] * cos(q) + R[1] * sin(q)) * sin(q)) * R.x +
            ((-R[0] * sin(q) + R[1] * cos(q)) * sin(q) +
             (R[0] * cos(q) + R[1] * sin(q)) * cos(q)) * R.y)
    assert gradient(P[0] * R[2], P) == P[2] * P.x + P[0] * P.z
Ejemplo n.º 4
0
    a = Symbol('a')
    assert gradient(0, R) == Vector(0)
    assert gradient(R[0], R) == R.x
    assert gradient(R[0]*R[1]*R[2], R) == \
           R[1]*R[2]*R.x + R[0]*R[2]*R.y + R[0]*R[1]*R.z
    assert gradient(2*R[0]**2, R) == 4*R[0]*R.x
    assert gradient(a*sin(R[1])/R[0], R) == \
           - a*sin(R[1])/R[0]**2*R.x + a*cos(R[1])/R[0]*R.y
    assert gradient(P[0]*P[1], R) == \
           (-R[0]*sin(2*q) + R[1]*cos(2*q))*R.x + \
           (R[0]*cos(2*q) + R[1]*sin(2*q))*R.y
    assert gradient(P[0]*R[2], P) == P[2]*P.x + P[0]*P.z


scalar_field = 2*R[0]**2*R[1]*R[2]
grad_field = gradient(scalar_field, R)
vector_field = R[1]**2*R.x + 3*R[0]*R.y + 5*R[1]*R[2]*R.z
curl_field = curl(vector_field, R)


def test_conservative():
    assert is_conservative(0) is True
    assert is_conservative(R.x) is True
    assert is_conservative(2 * R.x + 3 * R.y + 4 * R.z) is True
    assert is_conservative(R[1]*R[2]*R.x + R[0]*R[2]*R.y + R[0]*R[1]*R.z) is \
           True
    assert is_conservative(R[0] * R.y) is False
    assert is_conservative(grad_field) is True
    assert is_conservative(curl_field) is False
    assert is_conservative(4*R[0]*R[1]*R[2]*R.x + 2*R[0]**2*R[2]*R.y) is \
                           False
Ejemplo n.º 5
0
    a = Symbol('a')
    assert gradient(0, R) == Vector(0)
    assert gradient(R[0], R) == R.x
    assert gradient(R[0]*R[1]*R[2], R) == \
           R[1]*R[2]*R.x + R[0]*R[2]*R.y + R[0]*R[1]*R.z
    assert gradient(2*R[0]**2, R) == 4*R[0]*R.x
    assert gradient(a*sin(R[1])/R[0], R) == \
           - a*sin(R[1])/R[0]**2*R.x + a*cos(R[1])/R[0]*R.y
    assert gradient(P[0]*P[1], R) == \
           (-R[0]*sin(2*q) + R[1]*cos(2*q))*R.x + \
           (R[0]*cos(2*q) + R[1]*sin(2*q))*R.y
    assert gradient(P[0]*R[2], P) == P[2]*P.x + P[0]*P.z


scalar_field = 2*R[0]**2*R[1]*R[2]
grad_field = gradient(scalar_field, R)
vector_field = R[1]**2*R.x + 3*R[0]*R.y + 5*R[1]*R[2]*R.z
curl_field = curl(vector_field, R)


def test_conservative():
    assert is_conservative(0) is True
    assert is_conservative(R.x) is True
    assert is_conservative(2 * R.x + 3 * R.y + 4 * R.z) is True
    assert is_conservative(R[1]*R[2]*R.x + R[0]*R[2]*R.y + R[0]*R[1]*R.z) is \
           True
    assert is_conservative(R[0] * R.y) is False
    assert is_conservative(grad_field) is True
    assert is_conservative(curl_field) is False
    assert is_conservative(4*R[0]*R[1]*R[2]*R.x + 2*R[0]**2*R[2]*R.y) is \
                           False