How to use the sympy.Symbol function in sympy

To help you get started, we’ve selected a few sympy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ChairOfStructuralMechanicsTUM / Mechanics_Apps / System_of_Beams / testing_collection / test_cases.py View on Github external
def single_beam_trapezload_test(curr_doc: CurrentDoc):
    start_knot = Knot.Knot(0, 0, 0, ElSupEnum.SUPPORT_FIXED_END.value, 0)
    end_knot = Knot.Knot(1, 1, 0, ElSupEnum.SUPPORT_ROLLER_END.value,  0)
    q = Symbol('p')
    x = Symbol('x')
    l = Symbol('l')
    lineload = [0, q * x]
    temp_prop = TempProps.TempProps(0, 0, 0)
    knot_list = [[start_knot, end_knot]]
    elementlist = []
    ele = ElementCalculation(0, start_knot, end_knot, l, lineload, temp_prop)
    start_knot.add_coupled_el(0)
    end_knot.add_coupled_el(0)
    elementlist.append(ele)
    functions, x, l_list = CalculationElement(elementlist)
    testbox.print_graphs(functions, x, l_list, knot_list)
github ahkab / ahkab / tests / svf_biquad / test_svf-biquad.py View on Github external
testbench.test()

    if cli:
        r = ahkab.run(mycircuit, [symbolic_sim, ac_sim])
        E = r['symbolic'][0].as_symbol('E1')
        out_hp = sympy.limit(r['symbolic'][0]['VU1o'], E, sympy.oo, '+')
        out_bp = sympy.limit(r['symbolic'][0]['VU2o'], E, sympy.oo, '+')
        out_lp = sympy.limit(r['symbolic'][0]['VU3o'], E, sympy.oo, '+')
        out_hp = out_hp.simplify()
        out_bp = out_bp.simplify()
        out_lp = out_lp.simplify()
        print("VU1o =", out_hp)
        print("VU2o =", out_bp)
        print("VU3o =", out_lp)

        w = sympy.Symbol('w')
        out_hp = out_hp.subs({r['symbolic'][0].as_symbol('RF1'):10e3,
                              r['symbolic'][0].as_symbol('C10'):15e-9,
                              r['symbolic'][0].as_symbol('V1'):1,
                              r['symbolic'][0].as_symbol('s'):1j*w,
                              })
        out_bp = out_bp.subs({r['symbolic'][0].as_symbol('RF1'):10e3,
                              r['symbolic'][0].as_symbol('C10'):15e-9,
                              r['symbolic'][0].as_symbol('V1'):1,
                              r['symbolic'][0].as_symbol('s'):1j*w,
                              })
        out_lp = out_lp.subs({r['symbolic'][0].as_symbol('RF1'):10e3,
                              r['symbolic'][0].as_symbol('C10'):15e-9,
                              r['symbolic'][0].as_symbol('V1'):1,
                              r['symbolic'][0].as_symbol('s'):1j*w,
                              })
        out_lp = sympy.lambdify((w,), out_lp, modules='numpy')
github devitocodes / devito / tests / test_pickle.py View on Github external
def test_symbolics():
    a = Symbol('a')

    id = IntDiv(a, 3)
    pkl_id = pickle.dumps(id)
    new_id = pickle.loads(pkl_id)
    assert id == new_id

    ffp = FunctionFromPointer('foo', a, ['b', 'c'])
    pkl_ffp = pickle.dumps(ffp)
    new_ffp = pickle.loads(pkl_ffp)
    assert ffp == new_ffp

    li = ListInitializer(['a', 'b'])
    pkl_li = pickle.dumps(li)
    new_li = pickle.loads(pkl_li)
    assert li == new_li
github certik / sympyx / test_basic.py View on Github external
def test_args_type():
    x = Symbol("x")
    y = Symbol("y")
    z = Symbol("z")

    assert (x+y).type == ADD
    assert set((x+y).args) == set((x, y))
    assert set((x+y).args) != set((x, z))

    assert (x*y*z).type == MUL
    assert set((x*y*z).args) == set((x, y, z))

    assert (x**y).type == POW
    assert (x**y).args == (x, y)
    assert x.type == SYMBOL
    assert x.args in [(), None]
    assert Integer(5).type == INTEGER
    assert Integer(5).args in [(), None]
github certik / sympyx / test_basic.py View on Github external
def test_hash2():
    x = Symbol("x")
    y = Symbol("y")
    z = Symbol("z")
    a = Symbol("x")

    assert x*y+y*x == 2*x*y
    assert x*y-y*x == 0
    assert x*y+y*a == 2*x*y
    assert x*y-y*a == 0
github sfepy / sfepy / tests / test_semismooth_newton.py View on Github external
    k = sm.Matrix(7, 1, lambda i, j: sm.Symbol('k%d' % i))
github danilobellini / audiolazy / math / lowpass_highpass_bilinear.py View on Github external
Taylor/Mclaurin polynomial aproximation for the given function.
  The ``n`` (default 2) is the amount of aproximation terms for ``f``. Other
  arguments are keyword-only and will be passed to the ``f.series`` method.
  """
  return sum(Stream(f.series(n=None, **kwargs)).limit(n))


# Symbols used
p = Symbol("p", real=True)         # Laplace pole
f = Symbol("Omega", positive=True) # Frequency in rad/s (analog)
s = Symbol("s")                    # Laplace Transform complex variable

rate = Symbol("rate", positive=True) # Rate in samples/s

G = Symbol("G", positive=True)     # Digital gain (linear)
R = Symbol("R", real=True)         # Digital pole ("radius")
w = Symbol("omega", real=True)     # Frequency (rad/sample) usually in [0;pi]
z = Symbol("z")                    # Z-Transform complex variable

zinv = Symbol("z^-1")              # z ** -1


# Bilinear transform equation
print_header("Bilinear transformation method")
print("\nLaplace and Z Transforms are related by:")
pprint(Eq(z, exp(s / rate)))

print("\nBilinear transform approximation (no prewarping):")
z_num = exp( s / (2 * rate))
z_den = exp(-s / (2 * rate))
assert z_num / z_den == exp(s / rate)
z_bilinear = together(taylor(z_num, x=s, x0=0) / taylor(z_den, x=s, x0=0))
github materialsproject / pymatgen / pymatgen / analysis / elasticity / elastic.py View on Github external
Generates the pseudoinverse for a given set of strains.

    Args:
        strain_states (6xN array like): a list of voigt-notation
            "strain-states", i. e. perturbed indices of the strain
            as a function of the smallest strain e. g. (0, 1, 0, 0, 1, 0)
        order (int): order of pseudoinverse to calculate

    Returns:
        mis: pseudo inverses for each order tensor, these can
            be multiplied by the central difference derivative
            of the stress with respect to the strain state
        absent_syms: symbols of the tensor absent from the PI
            expression
    """
    s = sp.Symbol('s')
    nstates = len(strain_states)
    ni = np.array(strain_states)*s
    mis, absent_syms = [], []
    for degree in range(2, order + 1):
        cvec, carr = get_symbol_list(degree)
        sarr = np.zeros((nstates, 6), dtype=object)
        for n, strain_v in enumerate(ni):
            # Get expressions
            exps = carr.copy()
            for i in range(degree - 1):
                exps = np.dot(exps, strain_v)
            exps /= np.math.factorial(degree - 1)
            sarr[n] = [sp.diff(exp, s, degree - 1) for exp in exps]
        svec = sarr.ravel()
        present_syms = set.union(*[exp.atoms(sp.Symbol) for exp in svec])
        absent_syms += [set(cvec) - present_syms]
github cemagg / sucem-fem / sucemfem / Testing / Analytical / current_fillament_farfield.py View on Github external
## You should have received a copy of the GNU General Public License
## along with SUCEM. If not, see . 
##
## Contact: cemagga@gmail.com 
from __future__ import division

import sympy as sp
from sympy import sin, cos, exp, pi

import sys
from sucemfem.Consts import mu0, c0

omega, mu, L, beta, r, theta = sp.symbols(
    'omega mu L beta r theta')

I0 = sp.Symbol('I0')

E_theta = 1j*omega*mu*I0*L*exp(-1j*beta*r)/(4*pi*r)*sin(theta)* \
          sin((beta*L/2)*cos(theta))/((beta*L/2)*cos(theta))

def eval_E_theta(freq, L_val, I_val, theta_val, r_val=1):
    return complex(E_theta.evalf(subs={
        omega:2*pi*freq,
        mu:mu0,
        I0:I_val,
        L:L_val,
        beta:2*pi*freq/c0,
        r:r_val,
        theta:theta_val,
        }))
        
if __name__ == '__main__':
github sympy / sympy / sympy / physics / units / dimensions.py View on Github external
def parse_dim(dim):
            if isinstance(dim, string_types):
                dim = Dimension(Symbol(dim))
            elif isinstance(dim, Dimension):
                pass
            elif isinstance(dim, Symbol):
                dim = Dimension(dim)
            else:
                raise TypeError("%s wrong type" % dim)
            return dim