# M_hodnoty=completion(M_hodnoty, M_err*M_hodnoty) #SYMBOLICKA CAST tic = time.time() #inicializace symbolickych promennych predstavujici veliciny C = [] K = [] k_E = [] M = np.zeros((N_plyny, N), dtype=object) rozmisteni_plynu = np.array([1, 2, 3]) #vzestupne podle ID zony #TCE, TMH, MCH, MDC, PCH, PCE for k in np.arange(1, N_plyny + 1): # od jedne do N+1 (pocita se i venkovni prostredi) for i in np.arange(1, N + 1): C.append(Symbol('C_' + str(k) + str(i))) for k, i in enumerate(rozmisteni_plynu, 1): M[k - 1, i - 1] = Symbol('m' + str(k) + str(i)) for i in np.arange(1, N + 1): for j in np.arange(1, N + 1): if i == j: K.append(0) else: K.append(Symbol('R' + str(i) + str(j))) k_E.append(Symbol('Re' + str(i))) C = np.reshape(C, (N_plyny, N)) K = np.reshape(K, (N, N)) k_E = np.array(k_E)
def test_symbol(): mml = mp._print(Symbol("x")) assert mml.nodeName == 'ci' assert mml.childNodes[0].nodeValue == 'x' del mml mml = mp._print(Symbol("x^2")) assert mml.nodeName == 'ci' assert mml.childNodes[0].nodeName == 'mml:msup' assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x' assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '2' del mml mml = mp._print(Symbol("x__2")) assert mml.nodeName == 'ci' assert mml.childNodes[0].nodeName == 'mml:msup' assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x' assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '2' del mml mml = mp._print(Symbol("x_2")) assert mml.nodeName == 'ci' assert mml.childNodes[0].nodeName == 'mml:msub' assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x' assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '2' del mml mml = mp._print(Symbol("x^3_2")) assert mml.nodeName == 'ci' assert mml.childNodes[0].nodeName == 'mml:msubsup' assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x' assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '2' assert mml.childNodes[0].childNodes[2].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[2].childNodes[0].nodeValue == '3' del mml mml = mp._print(Symbol("x__3_2")) assert mml.nodeName == 'ci' assert mml.childNodes[0].nodeName == 'mml:msubsup' assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x' assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[0].nodeValue == '2' assert mml.childNodes[0].childNodes[2].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[2].childNodes[0].nodeValue == '3' del mml mml = mp._print(Symbol("x_2_a")) assert mml.nodeName == 'ci' assert mml.childNodes[0].nodeName == 'mml:msub' assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x' assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mrow' assert mml.childNodes[0].childNodes[1].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[0].childNodes[ 0].nodeValue == '2' assert mml.childNodes[0].childNodes[1].childNodes[1].nodeName == 'mml:mo' assert mml.childNodes[0].childNodes[1].childNodes[1].childNodes[ 0].nodeValue == ' ' assert mml.childNodes[0].childNodes[1].childNodes[2].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[2].childNodes[ 0].nodeValue == 'a' del mml mml = mp._print(Symbol("x^2^a")) assert mml.nodeName == 'ci' assert mml.childNodes[0].nodeName == 'mml:msup' assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x' assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mrow' assert mml.childNodes[0].childNodes[1].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[0].childNodes[ 0].nodeValue == '2' assert mml.childNodes[0].childNodes[1].childNodes[1].nodeName == 'mml:mo' assert mml.childNodes[0].childNodes[1].childNodes[1].childNodes[ 0].nodeValue == ' ' assert mml.childNodes[0].childNodes[1].childNodes[2].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[2].childNodes[ 0].nodeValue == 'a' del mml mml = mp._print(Symbol("x__2__a")) assert mml.nodeName == 'ci' assert mml.childNodes[0].nodeName == 'mml:msup' assert mml.childNodes[0].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[0].childNodes[0].nodeValue == 'x' assert mml.childNodes[0].childNodes[1].nodeName == 'mml:mrow' assert mml.childNodes[0].childNodes[1].childNodes[0].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[0].childNodes[ 0].nodeValue == '2' assert mml.childNodes[0].childNodes[1].childNodes[1].nodeName == 'mml:mo' assert mml.childNodes[0].childNodes[1].childNodes[1].childNodes[ 0].nodeValue == ' ' assert mml.childNodes[0].childNodes[1].childNodes[2].nodeName == 'mml:mi' assert mml.childNodes[0].childNodes[1].childNodes[2].childNodes[ 0].nodeValue == 'a' del mml
def test_settings(): raises(TypeError, lambda: mathml(Symbol("x"), method="garbage"))
def test_binomial(): x = Symbol('x') n = Symbol('n', integer=True) nz = Symbol('nz', integer=True, nonzero=True) k = Symbol('k', integer=True) kp = Symbol('kp', integer=True, positive=True) u = Symbol('u', negative=True) p = Symbol('p', positive=True) z = Symbol('z', zero=True) nt = Symbol('nt', integer=False) a = Symbol('a', integer=True, nonnegative=True) b = Symbol('b', integer=True, nonnegative=True) assert binomial(0, 0) == 1 assert binomial(1, 1) == 1 assert binomial(10, 10) == 1 assert binomial(n, z) == 1 assert binomial(1, 2) == 0 assert binomial(1, -1) == 0 assert binomial(-1, 1) == -1 assert binomial(-1, -1) == 1 assert binomial(S.Half, S.Half) == 1 assert binomial(-10, 1) == -10 assert binomial(-10, 7) == -11440 assert binomial(n, -1).func == binomial assert binomial(kp, -1) == 0 assert binomial(nz, 0) == 1 assert expand_func(binomial(n, 1)) == n assert expand_func(binomial(n, 2)) == n*(n - 1)/2 assert expand_func(binomial(n, n - 2)) == n*(n - 1)/2 assert expand_func(binomial(n, n - 1)) == n assert binomial(n, 3).func == binomial assert binomial(n, 3).expand(func=True) == n**3/6 - n**2/2 + n/3 assert expand_func(binomial(n, 3)) == n*(n - 2)*(n - 1)/6 assert binomial(n, n) == 1 assert binomial(n, n + 1).func == binomial # e.g. (-1, 0) == 1 assert binomial(kp, kp + 1) == 0 assert binomial(n, u).func == binomial assert binomial(kp, u) == 0 assert binomial(n, p).func == binomial assert binomial(n, k).func == binomial assert binomial(n, n + p).func == binomial assert binomial(kp, kp + p) == 0 assert expand_func(binomial(n, n - 3)) == n*(n - 2)*(n - 1)/6 assert binomial(n, k).is_integer assert binomial(nt, k).is_integer is None assert binomial(x, nt).is_integer is False assert binomial(gamma(25), 6) == 79232165267303928292058750056084441948572511312165380965440075720159859792344339983120618959044048198214221915637090855535036339620413440000 assert binomial(a, b).is_nonnegative is True
# Importa Symbol - possibilidade de operacoes com simbolos # Importa solve - permite solucao de equacoes from sympy import Symbol, solve # Define uma nova funcao def calcula_f(X): return x ** 2 - 4 * x + 3 print("\n" * 100) # Define x como uma variavel x = Symbol('x') # Resolve a equacao calcula_f = 0 y = calcula_f(x) resultado = solve(y) print("\n") print("Resultado da equacao x**2 - 4 + x + 3 = 0") print("x = ", resultado)
from sympy.sets import ConditionSet, Intersection, FiniteSet, EmptySet, Union, Contains from sympy import Symbol, Eq, S, Abs, sin, pi, Interval, And, Mod, oo, Function from sympy.testing.pytest import raises, XFAIL, warns_deprecated_sympy w = Symbol("w") x = Symbol("x") y = Symbol("y") z = Symbol("z") L = Symbol("lambda") f = Function("f") def test_CondSet(): sin_sols_principal = ConditionSet(x, Eq(sin(x), 0), Interval(0, 2 * pi, False, True)) assert pi in sin_sols_principal assert pi / 2 not in sin_sols_principal assert 3 * pi not in sin_sols_principal assert 5 in ConditionSet(x, x**2 > 4, S.Reals) assert 1 not in ConditionSet(x, x**2 > 4, S.Reals) # in this case, 0 is not part of the base set so # it can't be in any subset selected by the condition assert 0 not in ConditionSet(x, y > 5, Interval(1, 7)) # since 'in' requires a true/false, the following raises # an error because the given value provides no information # for the condition to evaluate (since the condition does # not depend on the dummy symbol): the result is `y > 5`. # In this case, ConditionSet is just acting like # Piecewise((Interval(1, 7), y > 5), (S.EmptySet, True)). raises(TypeError, lambda: 6 in ConditionSet(x, y > 5, Interval(1, 7)))
def test_factorial_rewrite(): n = Symbol('n', integer=True) k = Symbol('k', integer=True, nonnegative=True) assert factorial(n).rewrite(gamma) == gamma(n + 1) assert str(factorial(k).rewrite(Product)) == 'Product(_i, (_i, 1, k))'
Lambda, sin, Eq, Ne, Piecewise, factor, expand_log, cancel, expand, diff, pi, atan) from sympy.integrals.risch import ( gcdex_diophantine, frac_in, as_poly_1t, derivation, splitfactor, splitfactor_sqf, canonical_representation, hermite_reduce, polynomial_reduce, residue_reduce, residue_reduce_to_basic, integrate_primitive, integrate_hyperexponential_polynomial, integrate_hyperexponential, integrate_hypertangent_polynomial, integrate_nonlinear_no_specials, integer_powers, DifferentialExtension, risch_integrate, DecrementLevel, NonElementaryIntegral, recognize_log_derivative, recognize_derivative, laurent_series) from sympy.utilities.pytest import raises from sympy.abc import x, t, nu, z, a, y t0, t1, t2 = symbols('t:3') i = Symbol('i') def test_gcdex_diophantine(): assert gcdex_diophantine(Poly(x**4 - 2*x**3 - 6*x**2 + 12*x + 15), Poly(x**3 + x**2 - 4*x - 4), Poly(x**2 - 1)) == \ (Poly((-x**2 + 4*x - 3)/5), Poly((x**3 - 7*x**2 + 16*x - 10)/5)) def test_frac_in(): assert frac_in(Poly((x + 1)/x*t, t), x) == \ (Poly(t*x + t, x), Poly(x, x)) assert frac_in((x + 1)/x*t, x) == \ (Poly(t*x + t, x), Poly(x, x)) assert frac_in((Poly((x + 1)/x*t, t), Poly(t + 1, t)), x) == \ (Poly(t*x + t, x), Poly((1 + t)*x, x))
def test_issue_9324_powsimp_on_matrix_symbol(): M = MatrixSymbol('M', 10, 10) expr = powsimp(M, deep=True) assert expr == M assert expr.args[0] == Symbol('M')
# Chapter 4 Algebra and symbolic math with sympy # In[2]: ## working with expressions # In[4]: from sympy import Symbol x = Symbol('x') y = Symbol('y') # In[7]: from sympy import factor, expand expr = x**2 - y**2 factor(expr) # In[8]: factors = factor(expr)
from sympy import Wild from types import GeneratorType import inspect import re import urllib.request, json import requests from .util import serialize, deserialize from .util import sign_defaults import forge from sympy.abc import _clash import sympy _clash['rad'] = Symbol('rad') _clash['deg'] = Symbol('deg') def parse_expr(*args, **kwargs): try: return sympy.sympify(*args, **kwargs) except: raise NameError('cannot parse {}, {}'.format(args, kwargs)) def get_unit_quantities(): """returns a map of sympy units {symbol: quantity} """ subs = {} for k, v in list(sympy_units.__dict__.items()):
def __call__(self, equations, variables=None, method_options=None): logger.warn( "The 'independent' state updater is deprecated and might be " "removed in future versions of Brian.", 'deprecated_independent', once=True) method_options = extract_method_options(method_options, {}) if equations.is_stochastic: raise UnsupportedEquationsException('Cannot solve stochastic ' 'equations with this state ' 'updater') if variables is None: variables = {} diff_eqs = equations.get_substituted_expressions(variables) t = Symbol('t', real=True, positive=True) dt = Symbol('dt', real=True, positive=True) t0 = Symbol('t0', real=True, positive=True) code = [] for name, expression in diff_eqs: rhs = str_to_sympy(expression.code, variables) # We have to be careful and use the real=True assumption as well, # otherwise sympy doesn't consider the symbol a match to the content # of the equation var = Symbol(name, real=True) f = sp.Function(name) rhs = rhs.subs(var, f(t)) derivative = sp.Derivative(f(t), t) diff_eq = sp.Eq(derivative, rhs) # TODO: simplify=True sometimes fails with 0.7.4, see: # https://github.com/sympy/sympy/issues/2666 try: general_solution = sp.dsolve(diff_eq, f(t), simplify=True) except RuntimeError: general_solution = sp.dsolve(diff_eq, f(t), simplify=False) # Check whether this is an explicit solution if not getattr(general_solution, 'lhs', None) == f(t): raise UnsupportedEquationsException( 'Cannot explicitly solve: ' + str(diff_eq)) # Solve for C1 (assuming "var" as the initial value and "t0" as time) if general_solution.has(Symbol('C1')): if general_solution.has(Symbol('C2')): raise UnsupportedEquationsException( 'Too many constants in solution: %s' % str(general_solution)) constant_solution = sp.solve(general_solution, Symbol('C1')) if len(constant_solution) != 1: raise UnsupportedEquationsException( ("Couldn't solve for the constant " "C1 in : %s ") % str(general_solution)) constant = constant_solution[0].subs(t, t0).subs(f(t0), var) solution = general_solution.rhs.subs('C1', constant) else: solution = general_solution.rhs.subs(t, t0).subs(f(t0), var) # Evaluate the expression for one timestep solution = solution.subs(t, t + dt).subs(t0, t) # only try symplifying it -- it sometimes raises an error try: solution = solution.simplify() except ValueError: pass code.append(name + ' = ' + sympy_to_str(solution)) return '\n'.join(code)
def __call__(self, equations, variables=None, method_options=None): method_options = extract_method_options(method_options, {'simplify': True}) if equations.is_stochastic: raise UnsupportedEquationsException('Cannot solve stochastic ' 'equations with this state ' 'updater.') if variables is None: variables = {} # Get a representation of the ODE system in the form of # dX/dt = M*X + B varnames, matrix, constants = get_linear_system(equations, variables) # No differential equations, nothing to do (this occurs sometimes in the # test suite where the whole model is nothing more than something like # 'v : 1') if matrix.shape == (0, 0): return '' # Make sure that the matrix M is constant, i.e. it only contains # external variables or constant variables t = Symbol('t', real=True, positive=True) # Check for time dependence dt_value = variables['dt'].get_value( )[0] if 'dt' in variables else None # This will raise an error if we meet the symbol "t" anywhere # except as an argument of a locally constant function for entry in itertools.chain(matrix, constants): if not is_constant_over_dt(entry, variables, dt_value): raise UnsupportedEquationsException( ('Expression "{}" is not guaranteed to be constant over a ' 'time step').format(sympy_to_str(entry))) symbols = [Symbol(variable, real=True) for variable in varnames] solution = sp.solve_linear_system(matrix.row_join(constants), *symbols) if solution is None or set(symbols) != set(solution.keys()): raise UnsupportedEquationsException('Cannot solve the given ' 'equations with this ' 'stateupdater.') b = sp.ImmutableMatrix([solution[symbol] for symbol in symbols]) # Solve the system dt = Symbol('dt', real=True, positive=True) try: A = (matrix * dt).exp() except NotImplementedError: raise UnsupportedEquationsException('Cannot solve the given ' 'equations with this ' 'stateupdater.') if method_options['simplify']: A = A.applyfunc( lambda x: sp.factor_terms(sp.cancel(sp.signsimp(x)))) C = sp.ImmutableMatrix(A * b) - b _S = sp.MatrixSymbol('_S', len(varnames), 1) updates = A * _S + C updates = updates.as_explicit() # The solution contains _S[0, 0], _S[1, 0] etc. for the state variables, # replace them with the state variable names abstract_code = [] for idx, (variable, update) in enumerate(zip(varnames, updates)): rhs = update if rhs.has(I, re, im): raise UnsupportedEquationsException( 'The solution to the linear system ' 'contains complex values ' 'which is currently not implemented.') for row_idx, varname in enumerate(varnames): rhs = rhs.subs(_S[row_idx, 0], varname) # Do not overwrite the real state variables yet, the update step # of other state variables might still need the original values abstract_code.append('_' + variable + ' = ' + sympy_to_str(rhs)) # Update the state variables for variable in varnames: abstract_code.append( '{variable} = _{variable}'.format(variable=variable)) return '\n'.join(abstract_code)
from sympy.solvers import solve import matplotlib.pyplot as plt import math import numpy as np WP = 10 * 2 * np.pi #o 12Hz F = 10000 #!!!!!!!!! VCC = 15 A0 = 100000 VD = 1 #!!!!!!!!!!! RD = 500000 #SIMULAR Y VER!!!!!!!!!!! R0 = 1 #SIMULAR Y VER!!!!!!!!!! #w = 2*np.pi*F r1 = Symbol('R1', real=True, positive=True) r3 = Symbol('R3', real=True, positive=True) r4 = Symbol('R4', real=True, positive=True) r5 = Symbol('R5', real=True, positive=True) r6 = Symbol('R6', real=True, positive=True) r7 = Symbol('R7', real=True, positive=True) r8 = Symbol('R8', real=True, positive=True) c2 = Symbol('C2', real=True, positive=True) c6 = Symbol('C6', real=True, positive=True) a = Symbol('A', real=True, positive=True) #w = Symbol('w',real = True, positive = True) #wp = Symbol ('Wpppp',real = True, positive = True) f = Symbol('f', real=True, positive=True) #vcc = Symbol('Vcc',real = True, positive = True) #sr = Symbol('SR',real = True, positive = True) #vp = Symbol('Vp',real = True, positive = True)
def N(self): """ 4--7--3 p1=(-1,-1) | | p2=( 1,-1) 8 9 6 p3=( 1, 1) | | p4=(-1, 1) 1--5--2 p5=( 1-8-4 -> a=-1 5-9-7 a=0 2-6-3 a=1 1-5-2 -> b=-1 8-9-6 b=0 3-7-4 b=1 """ k1 = Symbol('k1') k2 = Symbol('k2') k3 = Symbol('k3') k4 = Symbol('k4') k5 = Symbol('k5') k6 = Symbol('k6') k7 = Symbol('k7') k8 = Symbol('k8') k9 = Symbol('k9') L12 = b + 1 L23 = a - 1 L34 = b - 1 L14 = a + 1 L68 = b L57 = a # corners N1 = k1 * L34 * L23 * L68 * L57 - 1 N2 = k2 * L14 * L34 * L68 * L57 - 1 N3 = k3 * L14 * L12 * L68 * L57 - 1 N4 = k4 * L12 * L23 * L68 * L57 - 1 #midside N5 = k5 * L14 * L23 * L34 * L68 - 1 N6 = k6 * L14 * L57 * L34 * L12 - 1 N7 = k7 * L14 * L23 * L68 * L12 - 1 N8 = k8 * L34 * L12 * L57 * L23 - 1 #center N9 = k9 * L34 * L12 * L14 * L23 - 1 k1 = self.solveABC(N1, k1, -1, -1) k2 = self.solveABC(N2, k2, 1, -1) k3 = self.solveABC(N3, k3, 1, 1) k4 = self.solveABC(N4, k4, -1, 1) #1-8-4 -> a=-1 #5-9-7 a=0 #2-6-3 a=1 #1-5-2 -> b=-1 #8-9-6 b=0 #3-7-4 b=1 k5 = self.solveABC(N5, k5, 0, -1) k6 = self.solveABC(N6, k6, 1, 0) k7 = self.solveABC(N7, k7, 0, 1) k8 = self.solveABC(N8, k8, -1, 0) k9 = self.solveABC(N9, k9, 0, 0) # corners N1 = k1 * L34 * L23 * L68 * L57 N2 = k2 * L14 * L34 * L68 * L57 N3 = k3 * L14 * L12 * L68 * L57 N4 = k4 * L12 * L23 * L68 * L57 #midside N5 = k5 * L14 * L23 * L34 * L68 N6 = k6 * L14 * L57 * L34 * L12 N7 = k7 * L14 * L23 * L68 * L12 N8 = k8 * L34 * L12 * L57 * L23 #center N9 = k9 * L34 * L12 * L14 * L23 print("CQUAD8") print("N1 = %s" % (N1)) print("N2 = %s" % (N2)) print("N3 = %s" % (N3)) print("N4 = %s" % (N4)) print("N5 = %s" % (N5)) print("N6 = %s" % (N6)) print("N7 = %s" % (N7)) print("N8 = %s" % (N8)) print("N9 = %s" % (N9))
def test_powsimp(): x, y, z, n = symbols('x,y,z,n') f = Function('f') assert powsimp(4**x * 2**(-x) * 2**(-x)) == 1 assert powsimp((-4)**x * (-2)**(-x) * 2**(-x)) == 1 assert powsimp(f(4**x * 2**(-x) * 2**(-x))) == f(4**x * 2**(-x) * 2**(-x)) assert powsimp(f(4**x * 2**(-x) * 2**(-x)), deep=True) == f(1) assert exp(x) * exp(y) == exp(x) * exp(y) assert powsimp(exp(x) * exp(y)) == exp(x + y) assert powsimp(exp(x) * exp(y) * 2**x * 2**y) == (2 * E)**(x + y) assert powsimp(exp(x)*exp(y)*2**x*2**y, combine='exp') == \ exp(x + y)*2**(x + y) assert powsimp(exp(x)*exp(y)*exp(2)*sin(x) + sin(y) + 2**x*2**y) == \ exp(2 + x + y)*sin(x) + sin(y) + 2**(x + y) assert powsimp(sin(exp(x) * exp(y))) == sin(exp(x) * exp(y)) assert powsimp(sin(exp(x) * exp(y)), deep=True) == sin(exp(x + y)) assert powsimp(x**2 * x**y) == x**(2 + y) # This should remain factored, because 'exp' with deep=True is supposed # to act like old automatic exponent combining. assert powsimp((1 + E*exp(E))*exp(-E), combine='exp', deep=True) == \ (1 + exp(1 + E))*exp(-E) assert powsimp((1 + E*exp(E))*exp(-E), deep=True) == \ (1 + exp(1 + E))*exp(-E) assert powsimp((1 + E * exp(E)) * exp(-E)) == (1 + exp(1 + E)) * exp(-E) assert powsimp((1 + E*exp(E))*exp(-E), combine='exp') == \ (1 + exp(1 + E))*exp(-E) assert powsimp((1 + E*exp(E))*exp(-E), combine='base') == \ (1 + E*exp(E))*exp(-E) x, y = symbols('x,y', nonnegative=True) n = Symbol('n', real=True) assert powsimp(y**n * (y / x)**(-n)) == x**n assert powsimp(x**(x**(x*y)*y**(x*y))*y**(x**(x*y)*y**(x*y)), deep=True) \ == (x*y)**(x*y)**(x*y) assert powsimp(2**(2**(2 * x) * x), deep=False) == 2**(2**(2 * x) * x) assert powsimp(2**(2**(2 * x) * x), deep=True) == 2**(x * 4**x) assert powsimp( exp(-x + exp(-x)*exp(-x*log(x))), deep=False, combine='exp') == \ exp(-x + exp(-x)*exp(-x*log(x))) assert powsimp( exp(-x + exp(-x)*exp(-x*log(x))), deep=False, combine='exp') == \ exp(-x + exp(-x)*exp(-x*log(x))) assert powsimp((x + y) / (3 * z), deep=False, combine='exp') == (x + y) / (3 * z) assert powsimp((x / 3 + y / 3) / z, deep=True, combine='exp') == (x / 3 + y / 3) / z assert powsimp(exp(x)/(1 + exp(x)*exp(y)), deep=True) == \ exp(x)/(1 + exp(x + y)) assert powsimp(x * y**(z**x * z**y), deep=True) == x * y**(z**(x + y)) assert powsimp((z**x * z**y)**x, deep=True) == (z**(x + y))**x assert powsimp(x * (z**x * z**y)**x, deep=True) == x * (z**(x + y))**x p = symbols('p', positive=True) assert powsimp((1 / x)**log(2) / x) == (1 / x)**(1 + log(2)) assert powsimp((1 / p)**log(2) / p) == p**(-1 - log(2)) # coefficient of exponent can only be simplified for positive bases assert powsimp(2**(2 * x)) == 4**x assert powsimp((-1)**(2 * x)) == (-1)**(2 * x) i = symbols('i', integer=True) assert powsimp((-1)**(2 * i)) == 1 assert powsimp((-1)**(-x)) != (-1)**x # could be 1/((-1)**x), but is not # force=True overrides assumptions assert powsimp((-1)**(2 * x), force=True) == 1 # rational exponents allow combining of negative terms w, n, m = symbols('w n m', negative=True) e = i / a # not a rational exponent if `a` is unknown ex = w**e * n**e * m**e assert powsimp(ex) == m**(i / a) * n**(i / a) * w**(i / a) e = i / 3 ex = w**e * n**e * m**e assert powsimp(ex) == (-1)**i * (-m * n * w)**(i / 3) e = (3 + i) / i ex = w**e * n**e * m**e assert powsimp(ex) == (-1)**(3 * e) * (-m * n * w)**e eq = x**(a * Rational(2, 3)) # eq != (x**a)**(2/3) (try x = -1 and a = 3 to see) assert powsimp(eq).exp == eq.exp == a * Rational(2, 3) # powdenest goes the other direction assert powsimp(2**(2 * x)) == 4**x assert powsimp(exp(p / 2)) == exp(p / 2) # issue 6368 eq = Mul(*[sqrt(Dummy(imaginary=True)) for i in range(3)]) assert powsimp(eq) == eq and eq.is_Mul assert all(powsimp(e) == e for e in (sqrt(x**a), sqrt(x**2))) # issue 8836 assert str(powsimp(exp(I * pi / 3) * root(-1, 3))) == '(-1)**(2/3)' # issue 9183 assert powsimp(-0.1**x) == -0.1**x # issue 10095 assert powsimp((1 / (2 * E))**oo) == (exp(-1) / 2)**oo # PR 13131 eq = sin(2 * x)**2 * sin(2.0 * x)**2 assert powsimp(eq) == eq # issue 14615 assert powsimp( x**2 * y**3 * (x * y**2)**Rational(3, 2)) == x * y * (x * y**2)**Rational(5, 2)
def N(self): """ 3 x x 1 4 2 3-2 -> a=0 4 a=1/2 1 a=1 1-3 -> b=0 4 b=1/2 2 b=1 1-4-2 -> c=0 3 c=1 p1 = (1,0,0) p2 = (0,1,0) p3 = (0,0,1) p4 = (0.5,0.5,0) """ k1 = Symbol('k1') k2 = Symbol('k2') k3 = Symbol('k3') k4 = Symbol('k4') k5 = Symbol('k5') k6 = Symbol('k6') # corners N1 = a + k1 * a * b N2 = b + k2 * a * b N3 = c + k3 * a * b # midside #N4 = (1-a-b-c-1) L13 = b L23 = a N4 = k4 * L13 * L23 - 1 k1 = self.solveABC(N1, k1, 0.5, 0.5, 0) k2 = self.solveABC(N2, k2, 0.5, 0.5, 0) k3 = self.solveABC(N3, k3, 0.5, 0.5, 1) k4 = self.solveABC(N4, k4, 0.5, 0.5, 0) # corners N1 = a + k1 * a * b N2 = b + k2 * a * b N3 = c + k3 * a * b # midside N4 = k4 * L13 * L23 #p1 = (1,0,0) assert self.subABC(N1, 0, 0, 0) == 0, self.subABC(N1, 0, 0, 0) assert self.subABC(N1, 1, 0, 0) == 1, self.subABC(N1, 1, 0, 0) assert self.subABC(N1, 0, 1, 0) == 0, self.subABC(N1, 0, 1, 0) assert self.subABC(N1, 0, 0, 1) == 0, self.subABC(N1, 0, 0, 1) #p2 = (0,1,0) assert self.subABC(N2, 0, 0, 0) == 0, self.subABC(N2, 0, 0, 0) assert self.subABC(N2, 1, 0, 0) == 0, self.subABC(N2, 1, 0, 0) assert self.subABC(N2, 0, 1, 0) == 1, self.subABC(N2, 0, 1, 0) assert self.subABC(N2, 0, 0, 1) == 0, self.subABC(N2, 0, 0, 1) #p3 = (0,0,1) assert self.subABC(N3, 0, 0, 0) == 0, self.subABC(N3, 0, 0, 0) assert self.subABC(N3, 1, 0, 0) == 0, self.subABC(N3, 1, 0, 0) assert self.subABC(N3, 0, 1, 0) == 0, self.subABC(N3, 0, 1, 0) assert self.subABC(N3, 0, 0, 1) == 1, self.subABC(N3, 0, 0, 1) #p4 = (0.5,0.5,0) assert N4.subs(a, 0.5).subs(b, 0.5) == 1, self.subABC(N4, 0.5, 0.5, 0) print("CTRIA4") print("N1 = %s" % (N1)) print("N2 = %s" % (N2)) print("N3 = %s" % (N3)) print("N4 = %s" % (N4))
def test_sort_symbols(): myexpr = parse_expr('x+rho+a+b+c') assert sort_symbols(myexpr.free_symbols) == (Symbol('a'), Symbol('b'), Symbol('c'), Symbol('rho'), Symbol('x'))
def test_factorial_series(): n = Symbol('n', integer=True) assert factorial(n).series(n, 0, 3) == \ 1 - n*EulerGamma + n**2*(EulerGamma**2/2 + pi**2/12) + O(n**3)
# Change 2a to 2*a pat_mis_mult = re.compile("\d{1}[a-zA-Z]{1}") missed_mult_signs = re.findall(pat_mis_mult, inp) for el in missed_mult_signs: pos = re.search(pat_mis_mult, inp) start_pos = pos.start() end_pos = pos.end() inp = inp[:start_pos + 1] + '*' + inp[end_pos - 1:] # set all strings with more than two chars to lower characters pat_mult_chars = re.compile("[a-zA-Z]{2,}") mult_chars = re.findall(pat_mult_chars, inp) for el in mult_chars: start_pos = inp.find(el) end_pos = start_pos + len(el) if inp[start_pos:end_pos].lower() in EXCLUDE_WORDS: if not inp[start_pos:end_pos].lower() == inp[start_pos:end_pos]: inp = inp[:start_pos] + inp[start_pos:end_pos].lower( ) + inp[end_pos:] return sympify(inp) if __name__ == "__main__": x = Symbol('x') q = Symbol('q') y = x**2 - 2 + 5 * q res = solveset(y, x, S.Reals) # print(res) a = 1
def test_factorial2(): n = Symbol('n', integer=True) assert factorial2(-1) == 1 assert factorial2(0) == 1 assert factorial2(7) == 105 assert factorial2(8) == 384 # The following is exhaustive tt = Symbol('tt', integer=True, nonnegative=True) tte = Symbol('tte', even=True, nonnegative=True) tpe = Symbol('tpe', even=True, positive=True) tto = Symbol('tto', odd=True, nonnegative=True) tf = Symbol('tf', integer=True, nonnegative=False) tfe = Symbol('tfe', even=True, nonnegative=False) tfo = Symbol('tfo', odd=True, nonnegative=False) ft = Symbol('ft', integer=False, nonnegative=True) ff = Symbol('ff', integer=False, nonnegative=False) fn = Symbol('fn', integer=False) nt = Symbol('nt', nonnegative=True) nf = Symbol('nf', nonnegative=False) nn = Symbol('nn') #Solves and Fixes Issue #10388 - This is the updated test for the same solved issue raises (ValueError, lambda: factorial2(oo)) raises (ValueError, lambda: factorial2(S(5)/2)) assert factorial2(n).is_integer is None assert factorial2(tt - 1).is_integer assert factorial2(tte - 1).is_integer assert factorial2(tpe - 3).is_integer assert factorial2(tto - 4).is_integer assert factorial2(tto - 2).is_integer assert factorial2(tf).is_integer is None assert factorial2(tfe).is_integer is None assert factorial2(tfo).is_integer is None assert factorial2(ft).is_integer is None assert factorial2(ff).is_integer is None assert factorial2(fn).is_integer is None assert factorial2(nt).is_integer is None assert factorial2(nf).is_integer is None assert factorial2(nn).is_integer is None assert factorial2(n).is_positive is None assert factorial2(tt - 1).is_positive is True assert factorial2(tte - 1).is_positive is True assert factorial2(tpe - 3).is_positive is True assert factorial2(tpe - 1).is_positive is True assert factorial2(tto - 2).is_positive is True assert factorial2(tto - 1).is_positive is True assert factorial2(tf).is_positive is None assert factorial2(tfe).is_positive is None assert factorial2(tfo).is_positive is None assert factorial2(ft).is_positive is None assert factorial2(ff).is_positive is None assert factorial2(fn).is_positive is None assert factorial2(nt).is_positive is None assert factorial2(nf).is_positive is None assert factorial2(nn).is_positive is None assert factorial2(tt).is_even is None assert factorial2(tt).is_odd is None assert factorial2(tte).is_even is None assert factorial2(tte).is_odd is None assert factorial2(tte + 2).is_even is True assert factorial2(tpe).is_even is True assert factorial2(tto).is_odd is True assert factorial2(tf).is_even is None assert factorial2(tf).is_odd is None assert factorial2(tfe).is_even is None assert factorial2(tfe).is_odd is None assert factorial2(tfo).is_even is False assert factorial2(tfo).is_odd is None
def solve_linear_system_nontrivial(A0, b0, dummy='x'): """Finds the non-trivial solution of singular linear systems of equations """ if not isinstance(A0, Matrix): raise TypeError("A should be a sympy Matrix") if not isinstance(b0, Matrix): raise TypeError("b should be a sympy Matrix") if A0.rows != b0.rows: raise ShapeError("Matrix size mismatch") M, N = A0.rows, A0.cols A, b = A0.copy(), b0.copy() #lower triangular part for i in range(0, min(M, N)): if A[i, i] == 0: for j in range(i + 1, M): if A[j, i] != 0: A.row_swap(i, j) b.row_swap(i, j) break for j in range(i + 1, M): if A[j, i] != 0: P = eye(M) P[j, i] = A[j, i] P[j, j] = -A[i, i] A = P * A b = P * b #A[j*N] = A[i,i]*A.row(j)-A[j,i]*A.row(i) #TODO should replace A=P*A #b[j] = A[i,i]*b[j]-A[j,i]*b[i] #upper triangular part for i in range(min(M, N) - 1, 0, -1): if A[i, i] != 0: for j in range(0, i): if A[j, i] != 0: P = eye(M) P[j, i] = A[j, i] P[j, j] = -A[i, i] A = P * A b = P * b #A[j*N] = A[i,i]*A.row(j)-A[j,i]*A.row(i) #TODO should replace A=P*A #b[j] = A[i,i]*b[j]-A[j,i]*b[i] #zero diagonals for i in range(min(M, N) - 2, -1, -1): if A[i, i] == 0: for j in range(i + 1, min(M, N)): if A[j, j] == 0: if A[i, j] != 0: A.row_swap(i, j) b.row_swap(i, j) for k in range(0, j): if A[k, j] != 0: A[k * N] = A[j, j] * A.row(k) - A[k, j] * A.row(j) b[k] = A[j, j] * b[k] - A[k, j] * b[j] break #solve n_dummies = 0 Conditions = [] #conditions expr_i==0 x = zeros(M, 1) #solution nnz = [0] * M #number of nonzeros in each row for i in range(0, M): for j in range(0, N): if A[i, j] != 0: nnz[i] += 1 nnz_dict = dict(zip(range(0, M), nnz)) variable_solved = dict(zip(range(0, N), [[False, 0]] * N)) for (i, v) in sorted(nnz_dict.items(), key=operator.itemgetter(1)): if v == 0: Conditions.append(b[i]) elif v == 1: for j in range(0, N): if A[i, j] != 0: variable_solved[j] = [True, b[i] / A[i, j]] x[j] = b[i] / A[i, j] break else: x_not_set = [] #variables not solved yet for j in range(0, N): if A[i, j] != 0 and variable_solved[j][0] == False: x_not_set.append(j) for k in range(1, len(x_not_set)): x_dummy_next = dummy + str(n_dummies) #next dummy variable n_dummies += 1 variable_solved[x_not_set[k]] = [True, Symbol(x_dummy_next)] x[x_not_set[k]] = Symbol(x_dummy_next) if len(x_not_set) > 0: x_ind = x_not_set[ 0] #the index to solve (x_not_set[i>0] are set to dummies) x_val = b[x_ind] #x_val:the value of the index to solve for j in range(0, N): if A[i, j] != 0 and variable_solved[j][0] == True: x_val -= A[i, j] * variable_solved[j][1] x_val /= A[i, x_ind] variable_solved[x_ind] = [True, x_val] x[x_ind] = x_val return [A, b, x, Conditions]
def test_subfactorial(): assert all(subfactorial(i) == ans for i, ans in enumerate( [1, 0, 1, 2, 9, 44, 265, 1854, 14833, 133496])) assert subfactorial(oo) == oo assert subfactorial(nan) == nan x = Symbol('x') assert subfactorial(x).rewrite(uppergamma) == uppergamma(x + 1, -1)/S.Exp1 tt = Symbol('tt', integer=True, nonnegative=True) tf = Symbol('tf', integer=True, nonnegative=False) tn = Symbol('tf', integer=True) ft = Symbol('ft', integer=False, nonnegative=True) ff = Symbol('ff', integer=False, nonnegative=False) fn = Symbol('ff', integer=False) nt = Symbol('nt', nonnegative=True) nf = Symbol('nf', nonnegative=False) nn = Symbol('nf') te = Symbol('te', even=True, nonnegative=True) to = Symbol('to', odd=True, nonnegative=True) assert subfactorial(tt).is_integer assert subfactorial(tf).is_integer is None assert subfactorial(tn).is_integer is None assert subfactorial(ft).is_integer is None assert subfactorial(ff).is_integer is None assert subfactorial(fn).is_integer is None assert subfactorial(nt).is_integer is None assert subfactorial(nf).is_integer is None assert subfactorial(nn).is_integer is None assert subfactorial(tt).is_nonnegative assert subfactorial(tf).is_nonnegative is None assert subfactorial(tn).is_nonnegative is None assert subfactorial(ft).is_nonnegative is None assert subfactorial(ff).is_nonnegative is None assert subfactorial(fn).is_nonnegative is None assert subfactorial(nt).is_nonnegative is None assert subfactorial(nf).is_nonnegative is None assert subfactorial(nn).is_nonnegative is None assert subfactorial(tt).is_even is None assert subfactorial(tt).is_odd is None assert subfactorial(te).is_odd is True assert subfactorial(to).is_even is True
from sympy import Symbol, solve #from sympy import Matrix a = Symbol('a') b = Symbol('b') c = Symbol('c') class FEM: def solve_abc(self, N, k, av, bv=0., cv=0.): N2 = self.subABC(N, av, bv, cv) #N2 = N.subs(a,av).subs(b,bv).subs(c,cv) self.log.debug("N = ", N) self.log.debug("Nb = ", N2) k = solve(N2, k) self.log.debug("k = ", k[0]) self.log.debug("") return k[0] def sub_abc(self, N, av, bv=0, cv=0): N2 = N.subs(a, av).subs(b, bv).subs(c, cv) return N2 class CTRIA3(FEM): def N(self): k1 = Symbol('k1') k2 = Symbol('k2') k3 = Symbol('k3') N1 = k1 * a - 1
from sympy import diff, Integral, Limit, sin, Symbol, Integer, Rational, cos, \ tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, E, I, oo, \ pi, GoldenRatio, EulerGamma, Sum, Eq, Ne, Ge, Lt, Float from sympy.core.compatibility import u from sympy.printing.mathml import mathml, MathMLPrinter from sympy.utilities.pytest import raises x = Symbol('x') y = Symbol('y') mp = MathMLPrinter() def test_printmethod(): assert mp.doprint(1 + x) == '<apply><plus/><ci>x</ci><cn>1</cn></apply>' def test_mathml_core(): mml_1 = mp._print(1 + x) assert mml_1.nodeName == 'apply' nodes = mml_1.childNodes assert len(nodes) == 3 assert nodes[0].nodeName == 'plus' assert nodes[0].hasChildNodes() is False assert nodes[0].nodeValue is None assert nodes[1].nodeName in ['cn', 'ci'] if nodes[1].nodeName == 'cn': assert nodes[1].childNodes[0].nodeValue == '1' assert nodes[2].childNodes[0].nodeValue == 'x' else: assert nodes[1].childNodes[0].nodeValue == 'x'
def N(self): """ 3 x 5 1 4 2 3-2-5 -> a=0 4 a=1/2 1 a=1 1-3 -> b=0 4-5 b=1/2 2 b=1 1-4-2 -> c=0 5 c=1/2 3 c=1 p1 = (1,0,0) p2 = (0,1,0) p3 = (0,0,1) p4 = (0.5,0.5, 0) p5 = (0, 0.5,0.5) """ k1 = Symbol('k1') k2 = Symbol('k2') k3 = Symbol('k3') k4 = Symbol('k4') k5 = Symbol('k5') k6 = Symbol('k6') k7 = Symbol('k7') k8 = Symbol('k8') #c = 1-a-b # corners N1 = a + k1 * a * b + k6 * b * c N2 = b + k2 * a * b + k7 * b * c N3 = c + k3 * a * b + k8 * b * c # midside #N4 = (1-a-b-c-1) N4 = k4 * a * b - 1 # from CTRIA6 node 4 N5 = k5 * b * c - 1 # from CTRIA6 node 5 k1 = self.solveABC(N1, k1, 0.5, 0.5, 0) k2 = self.solveABC(N2, k2, 0.5, 0.5, 0) k3 = self.solveABC(N3, k3, 0.5, 0.5, 0) k4 = self.solveABC(N4, k4, 0.5, 0.5, 0) k5 = self.solveABC(N5, k5, 0, 0.5, 0.5) # corners N1 = a + k1 * a * b + k6 * b * c N2 = b + k2 * a * b + k7 * b * c N3 = c + k3 * a * b + k8 * b * c # midside N4 = k4 * a * b N5 = k5 * b * c #p1 = (1,0,0) #p2 = (0,1,0) #p3 = (0,0,1) #p4 = (0.5,0.5, 0) #p5 = (0, 0.5,0.5) #p1 = (1,0,0) #assert self.subABC(N1,0,0,0) == 0,self.subABC(N1,0,0,0) # ??? #self.verifyN(N1,[1,0,0,0,0]) #self.verifyN(N2,[0,1,0,0,0]) #self.verifyN(N3,[0,0,1,0,0]) #self.verifyN(N4,[0,0,0,1,0]) #self.verifyN(N5,[0,0,0,0,1]) print("CTRIA4") print("N1 = %s" % (N1)) print("N2 = %s" % (N2)) print("N3 = %s" % (N3)) print("N4 = %s" % (N4)) print("N5 = %s" % (N5))
def test_mathml_greek(): mml = mp._print(Symbol('alpha')) assert mml.nodeName == 'ci' assert mml.childNodes[0].nodeValue == u('\N{GREEK SMALL LETTER ALPHA}') assert mp.doprint(Symbol('alpha')) == '<ci>α</ci>' assert mp.doprint(Symbol('beta')) == '<ci>β</ci>' assert mp.doprint(Symbol('gamma')) == '<ci>γ</ci>' assert mp.doprint(Symbol('delta')) == '<ci>δ</ci>' assert mp.doprint(Symbol('epsilon')) == '<ci>ε</ci>' assert mp.doprint(Symbol('zeta')) == '<ci>ζ</ci>' assert mp.doprint(Symbol('eta')) == '<ci>η</ci>' assert mp.doprint(Symbol('theta')) == '<ci>θ</ci>' assert mp.doprint(Symbol('iota')) == '<ci>ι</ci>' assert mp.doprint(Symbol('kappa')) == '<ci>κ</ci>' assert mp.doprint(Symbol('lambda')) == '<ci>λ</ci>' assert mp.doprint(Symbol('mu')) == '<ci>μ</ci>' assert mp.doprint(Symbol('nu')) == '<ci>ν</ci>' assert mp.doprint(Symbol('xi')) == '<ci>ξ</ci>' assert mp.doprint(Symbol('omicron')) == '<ci>ο</ci>' assert mp.doprint(Symbol('pi')) == '<ci>π</ci>' assert mp.doprint(Symbol('rho')) == '<ci>ρ</ci>' assert mp.doprint(Symbol('varsigma')) == '<ci>ς</ci>', mp.doprint( Symbol('varsigma')) assert mp.doprint(Symbol('sigma')) == '<ci>σ</ci>' assert mp.doprint(Symbol('tau')) == '<ci>τ</ci>' assert mp.doprint(Symbol('upsilon')) == '<ci>υ</ci>' assert mp.doprint(Symbol('phi')) == '<ci>φ</ci>' assert mp.doprint(Symbol('chi')) == '<ci>χ</ci>' assert mp.doprint(Symbol('psi')) == '<ci>ψ</ci>' assert mp.doprint(Symbol('omega')) == '<ci>ω</ci>' assert mp.doprint(Symbol('Alpha')) == '<ci>Α</ci>' assert mp.doprint(Symbol('Beta')) == '<ci>Β</ci>' assert mp.doprint(Symbol('Gamma')) == '<ci>Γ</ci>' assert mp.doprint(Symbol('Delta')) == '<ci>Δ</ci>' assert mp.doprint(Symbol('Epsilon')) == '<ci>Ε</ci>' assert mp.doprint(Symbol('Zeta')) == '<ci>Ζ</ci>' assert mp.doprint(Symbol('Eta')) == '<ci>Η</ci>' assert mp.doprint(Symbol('Theta')) == '<ci>Θ</ci>' assert mp.doprint(Symbol('Iota')) == '<ci>Ι</ci>' assert mp.doprint(Symbol('Kappa')) == '<ci>Κ</ci>' assert mp.doprint(Symbol('Lambda')) == '<ci>Λ</ci>' assert mp.doprint(Symbol('Mu')) == '<ci>Μ</ci>' assert mp.doprint(Symbol('Nu')) == '<ci>Ν</ci>' assert mp.doprint(Symbol('Xi')) == '<ci>Ξ</ci>' assert mp.doprint(Symbol('Omicron')) == '<ci>Ο</ci>' assert mp.doprint(Symbol('Pi')) == '<ci>Π</ci>' assert mp.doprint(Symbol('Rho')) == '<ci>Ρ</ci>' assert mp.doprint(Symbol('Sigma')) == '<ci>Σ</ci>' assert mp.doprint(Symbol('Tau')) == '<ci>Τ</ci>' assert mp.doprint(Symbol('Upsilon')) == '<ci>Υ</ci>' assert mp.doprint(Symbol('Phi')) == '<ci>Φ</ci>' assert mp.doprint(Symbol('Chi')) == '<ci>Χ</ci>' assert mp.doprint(Symbol('Psi')) == '<ci>Ψ</ci>' assert mp.doprint(Symbol('Omega')) == '<ci>Ω</ci>'
def N(self): """ .. code-block:: console N1 = a**2 N2 = b**2 N3 = c**3 N4 = 4*a*b N5 = 4*b*c N6 = 4*a*c 3 6 5 1 4 2 3-5-2 -> a=0 6-4 a=1/2 1 a=1 1-6-3 -> b=0 4-5 b=1/2 2 b=1 1-4-2 -> c=0 5-6 c=1/2 3 c=1 """ k1 = Symbol('k1') k2 = Symbol('k2') k3 = Symbol('k3') k4 = Symbol('k4') k5 = Symbol('k5') k6 = Symbol('k6') print(k1) L12 = c L13 = b L23 = a L45 = b - 1 / 2 L46 = a - 1 / 2 L56 = c - 1 / 2 # corners N1 = k1 * L23 * L46 - 1 N2 = k2 * L13 * L45 - 1 N3 = k3 * L12 * L56 - 1 # midside N4 = k4 * L13 * L23 - 1 N5 = k5 * L12 * L13 - 1 N6 = k6 * L12 * L23 - 1 print("N1 = %s" % (N1)) k1 = self.solveABC(N1, k1, 1, 0, 0) k2 = self.solveABC(N2, k2, 0, 1, 0) k3 = self.solveABC(N3, k3, 0, 0, 1) k4 = self.solveABC(N4, k4, 0.5, 0.5, 0) k5 = self.solveABC(N5, k5, 0, 0.5, 0.5) k6 = self.solveABC(N6, k6, 0.5, 0, 0.5) #print("k1 = ",k1) # corners N1 = k1 * L23 * L46 N2 = k2 * L13 * L45 N3 = k3 * L12 * L56 # midside N4 = k4 * L13 * L23 N5 = k5 * L12 * L13 N6 = k6 * L12 * L23 print("CTRIA6") print("N1 = %s" % (N1)) print("N2 = %s" % (N2)) print("N3 = %s" % (N3)) print("N4 = %s" % (N4)) print("N5 = %s" % (N5)) print("N6 = %s" % (N6))
def test_random_symbol_no_pspace(): x = RandomSymbol(Symbol('x')) assert x.pspace == PSpace()
from sympy.physics import msigma, mgamma # gamma^mu gamma0 = mgamma(0) gamma1 = mgamma(1) gamma2 = mgamma(2) gamma3 = mgamma(3) gamma5 = mgamma(5) # sigma_i sigma1 = msigma(1) sigma2 = msigma(2) sigma3 = msigma(3) E = Symbol("E", real=True) m = Symbol("m", real=True) def u(p, r): """ p = (p1, p2, p3); r = 0,1 """ if r not in [1, 2]: raise ValueError("Value of r should lie between 1 and 2") p1, p2, p3 = p if r == 1: ksi = Matrix([[1], [0]]) else: ksi = Matrix([[0], [1]]) a = (sigma1*p1 + sigma2*p2 + sigma3*p3) / (E + m)*ksi if a == 0: a = zeros(2, 1)