def test_parametric_region_list():

    point = Point(-5, 12)
    assert parametric_region_list(point) == [ParametricRegion((-5, 12))]

    e = Ellipse(Point(2, 8), 2, 6)
    assert parametric_region_list(e, t) == [ParametricRegion((2*cos(t) + 2, 6*sin(t) + 8), (t, 0, 2*pi))]

    c = Curve((t, t**3), (t, 5, 3))
    assert parametric_region_list(c) == [ParametricRegion((t, t**3), (t, 5, 3))]

    s = Segment(Point(2, 11, -6), Point(0, 2, 5))
    assert parametric_region_list(s, t) == [ParametricRegion((2 - 2*t, 11 - 9*t, 11*t - 6), (t, 0, 1))]
    s1 = Segment(Point(0, 0), (1, 0))
    assert parametric_region_list(s1, t) == [ParametricRegion((t, 0), (t, 0, 1))]
    s2 = Segment(Point(1, 2, 3), Point(1, 2, 5))
    assert parametric_region_list(s2, t) == [ParametricRegion((1, 2, 2*t + 3), (t, 0, 1))]
    s3 = Segment(Point(12, 56), Point(12, 56))
    assert parametric_region_list(s3) == [ParametricRegion((12, 56))]

    poly = Polygon((1,3), (-3, 8), (2, 4))
    assert parametric_region_list(poly, t) == [ParametricRegion((1 - 4*t, 5*t + 3), (t, 0, 1)), ParametricRegion((5*t - 3, 8 - 4*t), (t, 0, 1)), ParametricRegion((2 - t, 4 - t), (t, 0, 1))]

    p1 = Parabola(Point(0, 0), Line(Point(5, 8), Point(7,8)))
    raises(ValueError, lambda: parametric_region_list(p1))
Ejemplo n.º 2
0
def test_parametric_surfaceintegrals():

    semisphere = ParametricRegion((2*sin(phi)*cos(theta), 2*sin(phi)*sin(theta), 2*cos(phi)),\
                            (theta, 0, 2*pi), (phi, 0, pi/2))
    assert ParametricIntegral(C.z, semisphere) == 8*pi

    cylinder = ParametricRegion((sqrt(3)*cos(theta), sqrt(3)*sin(theta), z), (z, 0, 6), (theta, 0, 2*pi))
    assert ParametricIntegral(C.y, cylinder) == 0

    cone = ParametricRegion((v*cos(u), v*sin(u), v), (u, 0, 2*pi), (v, 0, 1))
    assert ParametricIntegral(C.x*C.i + C.y*C.j + C.z**4*C.k, cone) == pi/3

    triangle1 = ParametricRegion((x, y), (x, 0, 2), (y, 0, 10 - 5*x))
    triangle2 = ParametricRegion((x, y), (y, 0, 10 - 5*x), (x, 0, 2))
    assert ParametricIntegral(-15.6*C.y*C.k, triangle1) == ParametricIntegral(-15.6*C.y*C.k, triangle2)
    assert ParametricIntegral(C.z, triangle1) == 10*C.z
Ejemplo n.º 3
0
def test_volumeintegrals():

    cube = ParametricRegion((x, y, z), (x, 0, 1), (y, 0, 1), (z, 0, 1))
    assert ParametricIntegral(1, cube) == 1

    solidsphere = ParametricRegion((r*sin(phi)*cos(theta), r*sin(phi)*sin(theta), r*cos(phi)),\
                            (r, 0, 2), (theta, 0, 2*pi), (phi, 0, pi))
    assert ParametricIntegral(C.x**2 + C.y**2, solidsphere) == -256 * pi / 15

    region_under_plane1 = ParametricRegion((x, y, z), (x, 0, 3), (y, 0, -2*x/3 + 2),\
                                    (z, 0, 6 - 2*x - 3*y))
    region_under_plane2 = ParametricRegion((x, y, z), (x, 0, 3), (z, 0, 6 - 2*x - 3*y),\
                                    (y, 0, -2*x/3 + 2))

    assert ParametricIntegral(C.x*C.i + C.j - 100*C.k, region_under_plane1) == \
        ParametricIntegral(C.x*C.i + C.j - 100*C.k, region_under_plane2)
    assert ParametricIntegral(2 * C.x, region_under_plane2) == -9
Ejemplo n.º 4
0
def test_vector_integrate():
    halfdisc = ParametricRegion((r * cos(theta), r * sin(theta)), (r, -2, 2),
                                (theta, 0, pi))
    assert vector_integrate(C.x**2, halfdisc) == 4 * pi
    vector_integrate(C.x, ParametricRegion(
        (t, t**2), (t, 2, 3))) == -17 * sqrt(17) / 12 + 37 * sqrt(37) / 12

    assert vector_integrate(C.y**3 * C.z, (C.x, 0, 3),
                            (C.y, -1, 4)) == 765 * C.z / 4

    s1 = Segment(Point(0, 0), Point(0, 1))
    assert vector_integrate(-15 * C.y, s1) == S(-15) / 2
    s2 = Segment(Point(4, 3, 9), Point(1, 1, 7))
    assert vector_integrate(C.y * C.i, s2) == -6

    curve = Curve((sin(t), cos(t)), (t, 0, 2))
    assert vector_integrate(5 * C.z, curve) == 10 * C.z

    c1 = Circle(Point(2, 3), 6)
    assert vector_integrate(C.x * C.y, c1) == 72 * pi
    c2 = Circle(Point(0, 0), Point(1, 1), Point(1, 0))
    assert vector_integrate(1, c2) == c2.circumference

    triangle = Polygon((0, 0), (1, 0), (1, 1))
    assert vector_integrate(C.x * C.i - 14 * C.y * C.j, triangle) == 0
    p1, p2, p3, p4 = [(0, 0), (1, 0), (5, 1), (0, 1)]
    poly = Polygon(p1, p2, p3, p4)
    assert vector_integrate(-23 * C.z,
                            poly) == -161 * C.z - 23 * sqrt(17) * C.z

    point = Point(2, 3)
    assert vector_integrate(C.i * C.y - C.z, point) == ParametricIntegral(
        C.y * C.i, ParametricRegion((2, 3)))

    c3 = ImplicitRegion((x, y), x**2 + y**2 - 4)
    assert vector_integrate(45, c3) == 360 * pi
    c4 = ImplicitRegion((x, y), (x - 3)**2 + (y - 4)**2 - 9)
    assert vector_integrate(1, c4) == 12 * pi

    pl = Plane(Point(1, 1, 1), Point(2, 3, 4), Point(2, 2, 2))
    raises(ValueError, lambda: vector_integrate(C.x * C.z * C.i + C.k, pl))
Ejemplo n.º 5
0
def test_parametric_lineintegrals():
    halfcircle = ParametricRegion((4*cos(theta), 4*sin(theta)), (theta, -pi/2, pi/2))
    assert ParametricIntegral(C.x*C.y**4, halfcircle) == S(8192)/5

    curve = ParametricRegion((t, t**2, t**3), (t, 0, 1))
    field1 = 8*C.x**2*C.y*C.z*C.i + 5*C.z*C.j - 4*C.x*C.y*C.k
    assert ParametricIntegral(field1, curve) == 1
    line = ParametricRegion((4*t - 1, 2 - 2*t, t), (t, 0, 1))
    assert ParametricIntegral(C.x*C.z*C.i - C.y*C.z*C.k, line) == 3

    assert ParametricIntegral(4*C.x**3, ParametricRegion((1, t), (t, 0, 2))) == 8

    helix = ParametricRegion((cos(t), sin(t), 3*t), (t, 0, 4*pi))
    assert ParametricIntegral(C.x*C.y*C.z, helix) == -3*sqrt(10)*pi

    field2 = C.y*C.i + C.z*C.j + C.z*C.k
    assert ParametricIntegral(field2, ParametricRegion((cos(t), sin(t), t**2), (t, 0, pi))) == -5*pi/2 + pi**4/2
def test_ParametricRegion():

    point = ParametricRegion((3, 4))
    assert point.definition == (3, 4)
    assert point.parameters == ()
    assert point.limits == {}
    assert point.dimensions == 0

    # line x = y
    line_xy = ParametricRegion((y, y), (y, 1, 5))
    assert line_xy .definition == (y, y)
    assert line_xy.parameters == (y,)
    assert line_xy.dimensions == 1

    # line y = z
    line_yz = ParametricRegion((x,t,t), x, (t, 1, 2))
    assert line_yz.definition == (x,t,t)
    assert line_yz.parameters == (x, t)
    assert line_yz.limits == {t: (1, 2)}
    assert line_yz.dimensions == 1

    p1 = ParametricRegion((9*a, -16*b), (a, 0, 2), (b, -1, 5))
    assert p1.definition == (9*a, -16*b)
    assert p1.parameters == (a, b)
    assert p1.limits == {a: (0, 2), b: (-1, 5)}
    assert p1.dimensions == 2

    p2 = ParametricRegion((t, t**3), t)
    assert p2.parameters == (t,)
    assert p2.limits == {}
    assert p2.dimensions == 0

    circle = ParametricRegion((r*cos(theta), r*sin(theta)), r, (theta, 0, 2*pi))
    assert circle.definition == (r*cos(theta), r*sin(theta))
    assert circle.dimensions == 1

    halfdisc = ParametricRegion((r*cos(theta), r*sin(theta)), (r, -2, 2), (theta, 0, pi))
    assert halfdisc.definition == (r*cos(theta), r*sin(theta))
    assert halfdisc.parameters == (r, theta)
    assert halfdisc.limits == {r: (-2, 2), theta: (0, pi)}
    assert halfdisc.dimensions == 2

    ellipse = ParametricRegion((a*cos(t), b*sin(t)), (t, 0, 8))
    assert ellipse.parameters == (t,)
    assert ellipse.limits == {t: (0, 8)}
    assert ellipse.dimensions == 1

    cylinder = ParametricRegion((r*cos(theta), r*sin(theta), z), (r, 0, 1), (theta, 0, 2*pi), (z, 0, 4))
    assert cylinder.parameters == (r, theta, z)
    assert cylinder.dimensions == 3

    sphere = ParametricRegion((r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi)),
                                r, (theta, 0, 2*pi), (phi, 0, pi))
    assert sphere.definition == (r*sin(phi)*cos(theta),r*sin(phi)*sin(theta), r*cos(phi))
    assert sphere.parameters == (r, theta, phi)
    assert sphere.dimensions == 2

    raises(ValueError, lambda: ParametricRegion((a*t**2, 2*a*t), (a, -2)))
    raises(ValueError, lambda: ParametricRegion((a, b), (a**2, sin(b)), (a, 2, 4, 6)))
Ejemplo n.º 7
0
def test_parametricregion():

    point = ParametricRegion((), (3, 4), {})
    assert point.definition == (3, 4)
    assert point.parameters == ()
    assert point.limits == {}

    # line x = y
    line_xy = ParametricRegion(C, (C.y), limits={C.y: (-3, 3)})
    assert line_xy.definition == (C.y, )
    assert line_xy.parameters == (C.x, C.y, C.z)

    # line y = z
    line_yz = ParametricRegion((t), (C.x, t, t), limits={t: (1, 2)})
    assert line_yz.definition == (C.x, t, t)
    assert line_yz.parameters == (t, )

    p1 = ParametricRegion((a, b), (9 * a, -16 * b),
                          limits={
                              a: (0, 2),
                              b: (-1, 5)
                          })
    assert p1.definition == (9 * a, -16 * b)
    assert p1.parameters == (a, b)
    assert p1.limits == {a: (0, 2), b: (-1, 5)}

    p2 = ParametricRegion(t, (t, t**3))
    assert p2.parameters == (t, )
    assert p2.limits == {}

    circle = ParametricRegion((r, theta), (r * cos(theta), r * sin(theta)),
                              {theta: (0, 2 * pi)})
    assert circle.definition == (r * cos(theta), r * sin(theta))

    halfdisc = ParametricRegion((r, theta), (r * cos(theta), r * sin(theta)), {
        r: (-2, 2),
        theta: (0, pi)
    })
    assert halfdisc.definition == (r * cos(theta), r * sin(theta))
    assert halfdisc.parameters == (r, theta)
    assert halfdisc.limits == {r: (-2, 2), theta: (0, pi)}

    ellipse = ParametricRegion(t, (a * cos(t), b * sin(t)), {t: (0, 8)})
    assert ellipse.parameters == (t, )
    assert ellipse.limits == {t: (0, 8)}

    cylinder = ParametricRegion((r, theta, z),
                                (cos(theta), r * sin(theta), C.z), {
                                    theta: (0, 2 * pi),
                                    z: (0, 4)
                                })
    assert cylinder.parameters == (r, theta, z)

    sphere = ParametricRegion(
        (r, theta, phi),
        (r * sin(phi) * cos(theta), r * sin(phi) * sin(theta), r * cos(phi)), {
            theta: (0, 2 * pi),
            phi: (0, pi)
        })
    assert sphere.definition == (r * sin(phi) * cos(theta),
                                 r * sin(phi) * sin(theta), r * cos(phi))
    assert sphere.parameters == (r, theta, phi)

    raises(ValueError, lambda: ParametricRegion(
        (t), (a * t**2, 2 * a * t), {a: (-2, 2)}))
    raises(ValueError, lambda: ParametricRegion(
        (a, b), (a**2, sin(b)), {a: (2, 4, 6)}))