functions.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:Python-iBeacon-Scan 作者: NikNitro 项目源码 文件源码
def scalar_potential(field, coord_sys):
    """
    Returns the scalar potential function of a field in a given
    coordinate system (without the added integration constant).

    Parameters
    ==========

    field : Vector
        The vector field whose scalar potential function is to be
        calculated

    coord_sys : CoordSysCartesian
        The coordinate system to do the calculation in

    Examples
    ========

    >>> from sympy.vector import CoordSysCartesian
    >>> from sympy.vector import scalar_potential, gradient
    >>> R = CoordSysCartesian('R')
    >>> scalar_potential(R.k, R) == R.z
    True
    >>> scalar_field = 2*R.x**2*R.y*R.z
    >>> grad_field = gradient(scalar_field, R)
    >>> scalar_potential(grad_field, R)
    2*R.x**2*R.y*R.z

    """

    # Check whether field is conservative
    if not is_conservative(field):
        raise ValueError("Field is not conservative")
    if field == Vector.zero:
        return S(0)
    # Express the field exntirely in coord_sys
    # Subsitute coordinate variables also
    if not isinstance(coord_sys, CoordSysCartesian):
        raise TypeError("coord_sys must be a CoordSysCartesian")
    field = express(field, coord_sys, variables=True)
    dimensions = coord_sys.base_vectors()
    scalars = coord_sys.base_scalars()
    # Calculate scalar potential function
    temp_function = integrate(field.dot(dimensions[0]), scalars[0])
    for i, dim in enumerate(dimensions[1:]):
        partial_diff = diff(temp_function, scalars[i + 1])
        partial_diff = field.dot(dim) - partial_diff
        temp_function += integrate(partial_diff, scalars[i + 1])
    return temp_function
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号