コード例 #1
0
ファイル: test_medium.py プロジェクト: cklb/sympy
from sympy import sqrt, simplify
from sympy.physics.optics import Medium
from sympy.abc import epsilon, mu
from sympy.physics.units import speed_of_light, u0, e0, m, kg, s, A


c = speed_of_light.convert_to(m/s)
e0 = e0.convert_to(A**2*s**4/(kg*m**3))
u0 = u0.convert_to(m*kg/(A**2*s**2))


def test_medium():
    m1 = Medium('m1')
    assert m1.intrinsic_impedance == sqrt(u0/e0)
    assert m1.speed == 1/sqrt(e0*u0)
    assert m1.refractive_index == c*sqrt(e0*u0)
    assert m1.permittivity == e0
    assert m1.permeability == u0
    m2 = Medium('m2', epsilon, mu)
    assert m2.intrinsic_impedance == sqrt(mu/epsilon)
    assert m2.speed == 1/sqrt(epsilon*mu)
    assert m2.refractive_index == c*sqrt(epsilon*mu)
    assert m2.permittivity == epsilon
    assert m2.permeability == mu
    # Increasing electric permittivity and magnetic permeability
    # by small amount from its value in vacuum.
    m3 = Medium('m3', 9.0*10**(-12)*s**4*A**2/(m**3*kg), 1.45*10**(-6)*kg*m/(A**2*s**2))
    assert m3.refractive_index > m1.refractive_index
    assert m3 > m1
    # Decreasing electric permittivity and magnetic permeability
    # by small amount from its value in vacuum.
コード例 #2
0
**Contains**

* TWave
"""

from __future__ import print_function, division

__all__ = ['TWave']

from sympy import (sympify, pi, sin, cos, sqrt, Symbol, S, symbols, Derivative,
                   atan2)
from sympy.core.expr import Expr
from sympy.physics.units import speed_of_light, meter, second

c = speed_of_light.convert_to(meter / second)


class TWave(Expr):
    r"""
    This is a simple transverse sine wave travelling in a one-dimensional space.
    Basic properties are required at the time of creation of the object,
    but they can be changed later with respective methods provided.

    It is represented as :math:`A \times cos(k*x - \omega \times t + \phi )`,
    where :math:`A` is the amplitude, :math:`\omega` is the angular velocity,
    :math:`k` is the wavenumber (spatial frequency), :math:`x` is a spatial variable
    to represent the position on the dimension on which the wave propagates,
    and :math:`\phi` is the phase angle of the wave.

コード例 #3
0
from sympy import (symbols, Symbol, pi, sqrt, cos, sin, Derivative, Function,
                   simplify, I, atan2)
from sympy.abc import epsilon, mu
from sympy.functions.elementary.exponential import exp
from sympy.physics.units import speed_of_light, m, s
from sympy.physics.optics import TWave

c = speed_of_light.convert_to(m / s)


def test_twave():
    A1, phi1, A2, phi2, f = symbols('A1, phi1, A2, phi2, f')
    n = Symbol('n')  # Refractive index
    t = Symbol('t')  # Time
    x = Symbol('x')  # Spatial variable
    k = Symbol('k')  # Wavenumber
    E = Function('E')
    w1 = TWave(A1, f, phi1)
    w2 = TWave(A2, f, phi2)
    assert w1.amplitude == A1
    assert w1.frequency == f
    assert w1.phase == phi1
    assert w1.wavelength == c / (f * n)
    assert w1.time_period == 1 / f
    w3 = w1 + w2
    assert w3.amplitude == sqrt(A1**2 + 2 * A1 * A2 * cos(phi1 - phi2) + A2**2)
    assert w3.frequency == f
    assert w3.wavelength == c / (f * n)
    assert w3.time_period == 1 / f
    assert w3.angular_velocity == 2 * pi * f
    assert w3.wavenumber == 2 * pi * f * n / c
コード例 #4
0
ファイル: waves.py プロジェクト: KonstantinTogoi/sympy
**Contains**

* TWave
"""

from __future__ import print_function, division

__all__ = ['TWave']

from sympy import (sympify, pi, sin, cos, sqrt, Symbol, S,
    symbols, Derivative, atan2)
from sympy.core.expr import Expr
from sympy.physics.units import speed_of_light, meter, second


c = speed_of_light.convert_to(meter/second)


class TWave(Expr):

    r"""
    This is a simple transverse sine wave travelling in a one-dimensional space.
    Basic properties are required at the time of creation of the object,
    but they can be changed later with respective methods provided.

    It is represented as :math:`A \times cos(k*x - \omega \times t + \phi )`,
    where :math:`A` is the amplitude, :math:`\omega` is the angular velocity,
    :math:`k` is the wavenumber (spatial frequency), :math:`x` is a spatial variable
    to represent the position on the dimension on which the wave propagates,
    and :math:`\phi` is the phase angle of the wave.