本文整理汇总了Python中sympy.functions.sin函数的典型用法代码示例。如果您正苦于以下问题:Python sin函数的具体用法?Python sin怎么用?Python sin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_derivatives_in_spherical_coordinates
def test_derivatives_in_spherical_coordinates():
with GA_Printer():
X = (r, th, phi) = symbols("r theta phi")
curv = [[r * cos(phi) * sin(th), r * sin(phi) * sin(th), r * cos(th)], [1, r, r * sin(th)]]
(er, eth, ephi, grad) = MV.setup("e_r e_theta e_phi", metric="[1,1,1]", coords=X, curv=curv)
f = MV("f", "scalar", fct=True)
A = MV("A", "vector", fct=True)
B = MV("B", "grade2", fct=True)
assert str(f) == "f"
assert str(A) == "A__r*e_r + A__theta*e_theta + A__phi*e_phi"
assert str(B) == "B__rtheta*e_r^e_theta + B__rphi*e_r^e_phi + B__thetaphi*e_theta^e_phi"
assert str(grad * f) == "D{r}f*e_r + D{theta}f/r*e_theta + D{phi}f/(r*sin(theta))*e_phi"
assert (
str(grad | A)
== "D{r}A__r + 2*A__r/r + A__theta*cos(theta)/(r*sin(theta)) + D{theta}A__theta/r + D{phi}A__phi/(r*sin(theta))"
)
assert (
str(-MV.I * (grad ^ A))
== "((A__phi*cos(theta)/sin(theta) + D{theta}A__phi - D{phi}A__theta/sin(theta))/r)*e_r + (-D{r}A__phi - A__phi/r + D{phi}A__r/(r*sin(theta)))*e_theta + (D{r}A__theta + A__theta/r - D{theta}A__r/r)*e_phi"
)
assert (
str(grad ^ B)
== "(D{r}B__thetaphi - B__rphi*cos(theta)/(r*sin(theta)) + 2*B__thetaphi/r - D{theta}B__rphi/r + D{phi}B__rtheta/(r*sin(theta)))*e_r^e_theta^e_phi"
)
return
开发者ID:guanlongtianzi,项目名称:sympy,代码行数:29,代码来源:test_ga.py
示例2: test_algebraic
def test_algebraic():
x, y = symbols("x,y")
assert ask(x, "algebraic") == None
assert ask(I, "algebraic") == True
assert ask(2 * I, "algebraic") == True
assert ask(I / 3, "algebraic") == True
assert ask(sqrt(7), "algebraic") == True
assert ask(2 * sqrt(7), "algebraic") == True
assert ask(sqrt(7) / 3, "algebraic") == True
assert ask(I * sqrt(3), "algebraic") == True
assert ask(sqrt(1 + I * sqrt(3)), "algebraic") == True
assert ask((1 + I * sqrt(3) ** (S(17) / 31)), "algebraic") == True
assert ask((1 + I * sqrt(3) ** (S(17) / pi)), "algebraic") == False
assert ask(sin(7), "algebraic") == None
assert ask(sqrt(sin(7)), "algebraic") == None
assert ask(sqrt(y + I * sqrt(7)), "algebraic") == None
assert ask(oo, "algebraic") == False
assert ask(-oo, "algebraic") == False
assert ask(2.47, "algebraic") == False
开发者ID:sympy,项目名称:sympy,代码行数:27,代码来源:test_query.py
示例3: test_algebraic
def test_algebraic():
x, y = symbols('x,y')
assert ask(Q.algebraic(x)) == None
assert ask(Q.algebraic(I)) == True
assert ask(Q.algebraic(2*I)) == True
assert ask(Q.algebraic(I/3)) == True
assert ask(Q.algebraic(sqrt(7))) == True
assert ask(Q.algebraic(2*sqrt(7))) == True
assert ask(Q.algebraic(sqrt(7)/3)) == True
assert ask(Q.algebraic(I*sqrt(3))) == True
assert ask(Q.algebraic(sqrt(1+I*sqrt(3)))) == True
assert ask(Q.algebraic((1+I*sqrt(3)**(S(17)/31)))) == True
assert ask(Q.algebraic((1+I*sqrt(3)**(S(17)/pi)))) == False
assert ask(Q.algebraic(sin(7))) == None
assert ask(Q.algebraic(sqrt(sin(7)))) == None
assert ask(Q.algebraic(sqrt(y+I*sqrt(7)))) == None
assert ask(Q.algebraic(oo)) == False
assert ask(Q.algebraic(-oo)) == False
assert ask(Q.algebraic(2.47)) == False
开发者ID:lazovich,项目名称:sympy,代码行数:27,代码来源:test_query.py
示例4: test_Integral
def test_Integral():
assert mcode(Integral(sin(sin(x)), x)) == "Hold[Integrate[Sin[Sin[x]], x]]"
assert mcode(Integral(exp(-x**2 - y**2),
(x, -oo, oo),
(y, -oo, oo))) == \
"Hold[Integrate[Exp[-x^2 - y^2], {x, -Infinity, Infinity}, " \
"{y, -Infinity, Infinity}]]"
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:7,代码来源:test_mathematica.py
示例5: test_Matrix_printing
def test_Matrix_printing():
# Test returning a Matrix
mat = Matrix([x*y, Piecewise((2 + x, y>0), (y, True)), sin(z)])
A = MatrixSymbol('A', 3, 1)
p = rcode(mat, A)
assert p == (
"A[0] = x*y;\n"
"A[1] = ifelse(y > 0,x + 2,y);\n"
"A[2] = sin(z);")
# Test using MatrixElements in expressions
expr = Piecewise((2*A[2, 0], x > 0), (A[2, 0], True)) + sin(A[1, 0]) + A[0, 0]
p = rcode(expr)
assert p == ("ifelse(x > 0,2*A[2],A[2]) + sin(A[1]) + A[0]")
# Test using MatrixElements in a Matrix
q = MatrixSymbol('q', 5, 1)
M = MatrixSymbol('M', 3, 3)
m = Matrix([[sin(q[1,0]), 0, cos(q[2,0])],
[q[1,0] + q[2,0], q[3, 0], 5],
[2*q[4, 0]/q[1,0], sqrt(q[0,0]) + 4, 0]])
assert rcode(m, M) == (
"M[0] = sin(q[1]);\n"
"M[1] = 0;\n"
"M[2] = cos(q[2]);\n"
"M[3] = q[1] + q[2];\n"
"M[4] = q[3];\n"
"M[5] = 5;\n"
"M[6] = 2*q[4]/q[1];\n"
"M[7] = sqrt(q[0]) + 4;\n"
"M[8] = 0;")
开发者ID:chris-turner137,项目名称:sympy,代码行数:29,代码来源:test_rcode.py
示例6: test_functional_diffgeom_ch2
def test_functional_diffgeom_ch2():
x0, y0, r0, theta0 = symbols('x0, y0, r0, theta0', real=True)
x, y = symbols('x, y', real=True)
f = Function('f')
assert (R2_p.point_to_coords(R2_r.point([x0, y0])) ==
Matrix([sqrt(x0**2 + y0**2), atan2(y0, x0)]))
assert (R2_r.point_to_coords(R2_p.point([r0, theta0])) ==
Matrix([r0*cos(theta0), r0*sin(theta0)]))
assert R2_p.jacobian(R2_r, [r0, theta0]) == Matrix(
[[cos(theta0), -r0*sin(theta0)], [sin(theta0), r0*cos(theta0)]])
field = f(R2.x, R2.y)
p1_in_rect = R2_r.point([x0, y0])
p1_in_polar = R2_p.point([sqrt(x0**2 + y0**2), atan2(y0, x0)])
assert field.rcall(p1_in_rect) == f(x0, y0)
assert field.rcall(p1_in_polar) == f(x0, y0)
p_r = R2_r.point([x0, y0])
p_p = R2_p.point([r0, theta0])
assert R2.x(p_r) == x0
assert R2.x(p_p) == r0*cos(theta0)
assert R2.r(p_p) == r0
assert R2.r(p_r) == sqrt(x0**2 + y0**2)
assert R2.theta(p_r) == atan2(y0, x0)
h = R2.x*R2.r**2 + R2.y**3
assert h.rcall(p_r) == x0*(x0**2 + y0**2) + y0**3
assert h.rcall(p_p) == r0**3*sin(theta0)**3 + r0**3*cos(theta0)
开发者ID:abhik137,项目名称:sympy,代码行数:30,代码来源:test_function_diffgeom_book.py
示例7: test_algebraic
def test_algebraic():
x, y = symbols('x,y')
assert ask(x, 'algebraic') == None
assert ask(I, 'algebraic') == True
assert ask(2*I, 'algebraic') == True
assert ask(I/3, 'algebraic') == True
assert ask(sqrt(7), 'algebraic') == True
assert ask(2*sqrt(7), 'algebraic') == True
assert ask(sqrt(7)/3, 'algebraic') == True
assert ask(I*sqrt(3), 'algebraic') == True
assert ask(sqrt(1+I*sqrt(3)), 'algebraic') == True
assert ask((1+I*sqrt(3)**(S(17)/31)), 'algebraic') == True
assert ask((1+I*sqrt(3)**(S(17)/pi)), 'algebraic') == False
assert ask(sin(7), 'algebraic') == None
assert ask(sqrt(sin(7)), 'algebraic') == None
assert ask(sqrt(y+I*sqrt(7)), 'algebraic') == None
assert ask(oo, 'algebraic') == False
assert ask(-oo, 'algebraic') == False
assert ask(2.47, 'algebraic') == False
开发者ID:Aang,项目名称:sympy,代码行数:27,代码来源:test_query.py
示例8: _get_lambda_evaluator
def _get_lambda_evaluator(self):
fr = self.d_vars[0]
t = self.u_interval.v
p = self.v_interval.v
fx = fr*cos(t)*sin(p)
fy = fr*sin(t)*sin(p)
fz = fr*cos(p)
return lambdify([t,p], [fx,fy,fz])
开发者ID:Aang,项目名称:sympy,代码行数:8,代码来源:plot_modes.py
示例9: rs_sin
def rs_sin(p, x, prec):
"""
Sine of a series
Returns the series expansion of the sin of p, about 0.
Examples
========
>>> from sympy.polys.domains import QQ
>>> from sympy.polys.rings import ring
>>> from sympy.polys.ring_series import rs_sin
>>> R, x, y = ring('x, y', QQ)
>>> rs_sin(x + x*y, x, 4)
-1/6*x**3*y**3 - 1/2*x**3*y**2 - 1/2*x**3*y - 1/6*x**3 + x*y + x
See Also
========
sin
"""
R = x.ring
if not p:
return R(0)
if _has_constant_term(p, x):
zm = R.zero_monom
c = p[zm]
c_expr = c.as_expr()
if R.domain is EX:
t1, t2 = sin(c_expr), cos(c_expr)
elif isinstance(c, PolyElement):
try:
t1, t2 = R(sin(c_expr)), R(cos(c_expr))
except ValueError:
raise DomainError("The given series can't be expanded in this " "domain.")
else:
raise DomainError("The given series can't be expanded in this " "domain")
raise NotImplementedError
p1 = p - c
# Makes use of sympy cos, sin fuctions to evaluate the values of the cos/sin
# of the constant term.
return rs_sin(p1, x, prec) * t2 + rs_cos(p1, x, prec) * t1
# Series is calculated in terms of tan as its evaluation is fast.
if len(p) > 20 and p.ngens == 1:
t = rs_tan(p / 2, x, prec)
t2 = rs_square(t, x, prec)
p1 = rs_series_inversion(1 + t2, x, prec)
return rs_mul(p1, 2 * t, x, prec)
one = R(1)
n = 1
c = [0]
for k in range(2, prec + 2, 2):
c.append(one / n)
c.append(0)
n *= -k * (k + 1)
return rs_series_from_list(p, c, x, prec)
开发者ID:helpin,项目名称:sympy,代码行数:58,代码来源:ring_series.py
示例10: test_C99CodePrinter__precision
def test_C99CodePrinter__precision():
n = symbols('n', integer=True)
f32_printer = C99CodePrinter(dict(type_aliases={real: float32}))
f64_printer = C99CodePrinter(dict(type_aliases={real: float64}))
f80_printer = C99CodePrinter(dict(type_aliases={real: float80}))
assert f32_printer.doprint(sin(x+2.1)) == 'sinf(x + 2.1F)'
assert f64_printer.doprint(sin(x+2.1)) == 'sin(x + 2.1000000000000001)'
assert f80_printer.doprint(sin(x+Float('2.0'))) == 'sinl(x + 2.0L)'
for printer, suffix in zip([f32_printer, f64_printer, f80_printer], ['f', '', 'l']):
def check(expr, ref):
assert printer.doprint(expr) == ref.format(s=suffix, S=suffix.upper())
check(Abs(n), 'abs(n)')
check(Abs(x + 2.0), 'fabs{s}(x + 2.0{S})')
check(sin(x + 4.0)**cos(x - 2.0), 'pow{s}(sin{s}(x + 4.0{S}), cos{s}(x - 2.0{S}))')
check(exp(x*8.0), 'exp{s}(8.0{S}*x)')
check(exp2(x), 'exp2{s}(x)')
check(expm1(x*4.0), 'expm1{s}(4.0{S}*x)')
check(Mod(n, 2), '((n) % (2))')
check(Mod(2*n + 3, 3*n + 5), '((2*n + 3) % (3*n + 5))')
check(Mod(x + 2.0, 3.0), 'fmod{s}(1.0{S}*x + 2.0{S}, 3.0{S})')
check(Mod(x, 2.0*x + 3.0), 'fmod{s}(1.0{S}*x, 2.0{S}*x + 3.0{S})')
check(log(x/2), 'log{s}((1.0{S}/2.0{S})*x)')
check(log10(3*x/2), 'log10{s}((3.0{S}/2.0{S})*x)')
check(log2(x*8.0), 'log2{s}(8.0{S}*x)')
check(log1p(x), 'log1p{s}(x)')
check(2**x, 'pow{s}(2, x)')
check(2.0**x, 'pow{s}(2.0{S}, x)')
check(x**3, 'pow{s}(x, 3)')
check(x**4.0, 'pow{s}(x, 4.0{S})')
check(sqrt(3+x), 'sqrt{s}(x + 3)')
check(Cbrt(x-2.0), 'cbrt{s}(x - 2.0{S})')
check(hypot(x, y), 'hypot{s}(x, y)')
check(sin(3.*x + 2.), 'sin{s}(3.0{S}*x + 2.0{S})')
check(cos(3.*x - 1.), 'cos{s}(3.0{S}*x - 1.0{S})')
check(tan(4.*y + 2.), 'tan{s}(4.0{S}*y + 2.0{S})')
check(asin(3.*x + 2.), 'asin{s}(3.0{S}*x + 2.0{S})')
check(acos(3.*x + 2.), 'acos{s}(3.0{S}*x + 2.0{S})')
check(atan(3.*x + 2.), 'atan{s}(3.0{S}*x + 2.0{S})')
check(atan2(3.*x, 2.*y), 'atan2{s}(3.0{S}*x, 2.0{S}*y)')
check(sinh(3.*x + 2.), 'sinh{s}(3.0{S}*x + 2.0{S})')
check(cosh(3.*x - 1.), 'cosh{s}(3.0{S}*x - 1.0{S})')
check(tanh(4.0*y + 2.), 'tanh{s}(4.0{S}*y + 2.0{S})')
check(asinh(3.*x + 2.), 'asinh{s}(3.0{S}*x + 2.0{S})')
check(acosh(3.*x + 2.), 'acosh{s}(3.0{S}*x + 2.0{S})')
check(atanh(3.*x + 2.), 'atanh{s}(3.0{S}*x + 2.0{S})')
check(erf(42.*x), 'erf{s}(42.0{S}*x)')
check(erfc(42.*x), 'erfc{s}(42.0{S}*x)')
check(gamma(x), 'tgamma{s}(x)')
check(loggamma(x), 'lgamma{s}(x)')
check(ceiling(x + 2.), "ceil{s}(x + 2.0{S})")
check(floor(x + 2.), "floor{s}(x + 2.0{S})")
check(fma(x, y, -z), 'fma{s}(x, y, -z)')
check(Max(x, 8.0, x**4.0), 'fmax{s}(8.0{S}, fmax{s}(x, pow{s}(x, 4.0{S})))')
check(Min(x, 2.0), 'fmin{s}(2.0{S}, x)')
开发者ID:Lenqth,项目名称:sympy,代码行数:57,代码来源:test_ccode.py
示例11: test_trigintegrate_mixed
def test_trigintegrate_mixed():
assert trigintegrate(sin(x)*sec(x), x) == -log(sin(x)**2 - 1)/2
assert trigintegrate(sin(x)*csc(x), x) == x
assert trigintegrate(sin(x)*cot(x), x) == sin(x)
assert trigintegrate(cos(x)*sec(x), x) == x
assert trigintegrate(cos(x)*csc(x), x) == log(cos(x)**2 - 1)/2
assert trigintegrate(cos(x)*tan(x), x) == -cos(x)
assert trigintegrate(cos(x)*cot(x), x) == log(cos(x) - 1)/2 \
- log(cos(x) + 1)/2 + cos(x)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:10,代码来源:test_trigonometry.py
示例12: test_functional_exponent
def test_functional_exponent():
t = standard_transformations + (convert_xor, function_exponentiation)
x = Symbol('x')
y = Symbol('y')
a = Symbol('a')
yfcn = Function('y')
assert parse_expr("sin^2(x)", transformations=t) == (sin(x))**2
assert parse_expr("sin^y(x)", transformations=t) == (sin(x))**y
assert parse_expr("exp^y(x)", transformations=t) == (exp(x))**y
assert parse_expr("E^y(x)", transformations=t) == exp(yfcn(x))
assert parse_expr("a^y(x)", transformations=t) == a**(yfcn(x))
开发者ID:bjodah,项目名称:sympy,代码行数:11,代码来源:test_sympy_parser.py
示例13: test_bounded
def test_bounded():
x, y = symbols('xy')
assert ask(x, Q.bounded) == False
assert ask(x, Q.bounded, Assume(x, Q.bounded)) == True
assert ask(x, Q.bounded, Assume(y, Q.bounded)) == False
assert ask(x, Q.bounded, Assume(x, Q.complex)) == False
assert ask(x+1, Q.bounded) == False
assert ask(x+1, Q.bounded, Assume(x, Q.bounded)) == True
assert ask(x+y, Q.bounded) == None
assert ask(x+y, Q.bounded, Assume(x, Q.bounded)) == False
assert ask(x+1, Q.bounded, Assume(x, Q.bounded) & \
Assume(y, Q.bounded)) == True
assert ask(2*x, Q.bounded) == False
assert ask(2*x, Q.bounded, Assume(x, Q.bounded)) == True
assert ask(x*y, Q.bounded) == None
assert ask(x*y, Q.bounded, Assume(x, Q.bounded)) == False
assert ask(x*y, Q.bounded, Assume(x, Q.bounded) & \
Assume(y, Q.bounded)) == True
assert ask(x**2, Q.bounded) == False
assert ask(2**x, Q.bounded) == False
assert ask(2**x, Q.bounded, Assume(x, Q.bounded)) == True
assert ask(x**x, Q.bounded) == False
assert ask(Rational(1,2) ** x, Q.bounded) == True
assert ask(x ** Rational(1,2), Q.bounded) == False
# sign function
assert ask(sign(x), Q.bounded) == True
assert ask(sign(x), Q.bounded, Assume(x, Q.bounded, False)) == True
# exponential functions
assert ask(log(x), Q.bounded) == False
assert ask(log(x), Q.bounded, Assume(x, Q.bounded)) == True
assert ask(exp(x), Q.bounded) == False
assert ask(exp(x), Q.bounded, Assume(x, Q.bounded)) == True
assert ask(exp(2), Q.bounded) == True
# trigonometric functions
assert ask(sin(x), Q.bounded) == True
assert ask(sin(x), Q.bounded, Assume(x, Q.bounded, False)) == True
assert ask(cos(x), Q.bounded) == True
assert ask(cos(x), Q.bounded, Assume(x, Q.bounded, False)) == True
assert ask(2*sin(x), Q.bounded) == True
assert ask(sin(x)**2, Q.bounded) == True
assert ask(cos(x)**2, Q.bounded) == True
assert ask(cos(x) + sin(x), Q.bounded) == True
开发者ID:Aang,项目名称:sympy,代码行数:48,代码来源:test_query.py
示例14: test_bounded
def test_bounded():
x, y = symbols('x,y')
assert ask(Q.bounded(x)) == False
assert ask(Q.bounded(x), Q.bounded(x)) == True
assert ask(Q.bounded(x), Q.bounded(y)) == False
assert ask(Q.bounded(x), Q.complex(x)) == False
assert ask(Q.bounded(x+1)) == False
assert ask(Q.bounded(x+1), Q.bounded(x)) == True
assert ask(Q.bounded(x+y)) == None
assert ask(Q.bounded(x+y), Q.bounded(x)) == False
assert ask(Q.bounded(x+1), Q.bounded(x) & Q.bounded(y)) == True
assert ask(Q.bounded(2*x)) == False
assert ask(Q.bounded(2*x), Q.bounded(x)) == True
assert ask(Q.bounded(x*y)) == None
assert ask(Q.bounded(x*y), Q.bounded(x)) == False
assert ask(Q.bounded(x*y), Q.bounded(x) & Q.bounded(y)) == True
assert ask(Q.bounded(x**2)) == False
assert ask(Q.bounded(2**x)) == False
assert ask(Q.bounded(2**x), Q.bounded(x)) == True
assert ask(Q.bounded(x**x)) == False
assert ask(Q.bounded(Rational(1,2) ** x)) == None
assert ask(Q.bounded(Rational(1,2) ** x), Q.positive(x)) == True
assert ask(Q.bounded(Rational(1,2) ** x), Q.negative(x)) == False
assert ask(Q.bounded(sqrt(x))) == False
# sign function
assert ask(Q.bounded(sign(x))) == True
assert ask(Q.bounded(sign(x)), ~Q.bounded(x)) == True
# exponential functions
assert ask(Q.bounded(log(x))) == False
assert ask(Q.bounded(log(x)), Q.bounded(x)) == True
assert ask(Q.bounded(exp(x))) == False
assert ask(Q.bounded(exp(x)), Q.bounded(x)) == True
assert ask(Q.bounded(exp(2))) == True
# trigonometric functions
assert ask(Q.bounded(sin(x))) == True
assert ask(Q.bounded(sin(x)), ~Q.bounded(x)) == True
assert ask(Q.bounded(cos(x))) == True
assert ask(Q.bounded(cos(x)), ~Q.bounded(x)) == True
assert ask(Q.bounded(2*sin(x))) == True
assert ask(Q.bounded(sin(x)**2)) == True
assert ask(Q.bounded(cos(x)**2)) == True
assert ask(Q.bounded(cos(x) + sin(x))) == True
开发者ID:lazovich,项目名称:sympy,代码行数:48,代码来源:test_query.py
示例15: test_octave_piecewise
def test_octave_piecewise():
expr = Piecewise((x, x < 1), (x**2, True))
assert mcode(expr) == "((x < 1).*(x) + (~(x < 1)).*(x.^2))"
assert mcode(expr, assign_to="r") == (
"r = ((x < 1).*(x) + (~(x < 1)).*(x.^2));")
assert mcode(expr, assign_to="r", inline=False) == (
"if (x < 1)\n"
" r = x;\n"
"else\n"
" r = x.^2;\n"
"end")
expr = Piecewise((x**2, x < 1), (x**3, x < 2), (x**4, x < 3), (x**5, True))
expected = ("((x < 1).*(x.^2) + (~(x < 1)).*( ...\n"
"(x < 2).*(x.^3) + (~(x < 2)).*( ...\n"
"(x < 3).*(x.^4) + (~(x < 3)).*(x.^5))))")
assert mcode(expr) == expected
assert mcode(expr, assign_to="r") == "r = " + expected + ";"
assert mcode(expr, assign_to="r", inline=False) == (
"if (x < 1)\n"
" r = x.^2;\n"
"elseif (x < 2)\n"
" r = x.^3;\n"
"elseif (x < 3)\n"
" r = x.^4;\n"
"else\n"
" r = x.^5;\n"
"end")
# Check that Piecewise without a True (default) condition error
expr = Piecewise((x, x < 1), (x**2, x > 1), (sin(x), x > 0))
raises(ValueError, lambda: mcode(expr))
开发者ID:ChaliZhg,项目名称:sympy,代码行数:30,代码来源:test_octave.py
示例16: test_julia_piecewise
def test_julia_piecewise():
expr = Piecewise((x, x < 1), (x**2, True))
assert julia_code(expr) == "((x < 1) ? (x) : (x.^2))"
assert julia_code(expr, assign_to="r") == (
"r = ((x < 1) ? (x) : (x.^2))")
assert julia_code(expr, assign_to="r", inline=False) == (
"if (x < 1)\n"
" r = x\n"
"else\n"
" r = x.^2\n"
"end")
expr = Piecewise((x**2, x < 1), (x**3, x < 2), (x**4, x < 3), (x**5, True))
expected = ("((x < 1) ? (x.^2) :\n"
"(x < 2) ? (x.^3) :\n"
"(x < 3) ? (x.^4) : (x.^5))")
assert julia_code(expr) == expected
assert julia_code(expr, assign_to="r") == "r = " + expected
assert julia_code(expr, assign_to="r", inline=False) == (
"if (x < 1)\n"
" r = x.^2\n"
"elseif (x < 2)\n"
" r = x.^3\n"
"elseif (x < 3)\n"
" r = x.^4\n"
"else\n"
" r = x.^5\n"
"end")
# Check that Piecewise without a True (default) condition error
expr = Piecewise((x, x < 1), (x**2, x > 1), (sin(x), x > 0))
raises(ValueError, lambda: julia_code(expr))
开发者ID:asmeurer,项目名称:sympy,代码行数:30,代码来源:test_julia.py
示例17: test_Sum
def test_Sum():
assert mcode(Sum(sin(x), (x, 0, 10))) == "Hold[Sum[Sin[x], {x, 0, 10}]]"
assert mcode(Sum(exp(-x**2 - y**2),
(x, -oo, oo),
(y, -oo, oo))) == \
"Hold[Sum[Exp[-x^2 - y^2], {x, -Infinity, Infinity}, " \
"{y, -Infinity, Infinity}]]"
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:7,代码来源:test_mathematica.py
示例18: test_functional_diffgeom_ch3
def test_functional_diffgeom_ch3():
x0, y0 = symbols('x0, y0', real=True)
x, y, t = symbols('x, y, t', real=True)
f = Function('f')
b1 = Function('b1')
b2 = Function('b2')
p_r = R2_r.point([x0, y0])
s_field = f(R2.x, R2.y)
v_field = b1(R2.x)*R2.e_x + b2(R2.y)*R2.e_y
assert v_field.rcall(s_field).rcall(p_r).doit() == b1(
x0)*Derivative(f(x0, y0), x0) + b2(y0)*Derivative(f(x0, y0), y0)
assert R2.e_x(R2.r**2).rcall(p_r) == 2*x0
v = R2.e_x + 2*R2.e_y
s = R2.r**2 + 3*R2.x
assert v.rcall(s).rcall(p_r).doit() == 2*x0 + 4*y0 + 3
circ = -R2.y*R2.e_x + R2.x*R2.e_y
series = intcurve_series(circ, t, R2_r.point([1, 0]), coeffs=True)
series_x, series_y = zip(*series)
assert all(
[term == cos(t).taylor_term(i, t) for i, term in enumerate(series_x)])
assert all(
[term == sin(t).taylor_term(i, t) for i, term in enumerate(series_y)])
开发者ID:abhik137,项目名称:sympy,代码行数:25,代码来源:test_function_diffgeom_book.py
示例19: test_functional_diffgeom_ch4
def test_functional_diffgeom_ch4():
x0, y0, theta0 = symbols('x0, y0, theta0', real=True)
x, y, r, theta = symbols('x, y, r, theta', real=True)
r0 = symbols('r0', positive=True)
f = Function('f')
b1 = Function('b1')
b2 = Function('b2')
p_r = R2_r.point([x0, y0])
p_p = R2_p.point([r0, theta0])
f_field = b1(R2.x,R2.y)*R2.dx + b2(R2.x,R2.y)*R2.dy
assert f_field(R2.e_x)(p_r) == b1(x0, y0)
assert f_field(R2.e_y)(p_r) == b2(x0, y0)
s_field_r = f(R2.x,R2.y)
df = Differential(s_field_r)
assert df(R2.e_x)(p_r).doit() == Derivative(f(x0, y0), x0)
assert df(R2.e_y)(p_r).doit() == Derivative(f(x0, y0), y0)
s_field_p = f(R2.r,R2.theta)
df = Differential(s_field_p)
assert trigsimp(df(R2.e_x)(p_p).doit()) == cos(theta0)*Derivative(f(r0, theta0), r0) - sin(theta0)*Derivative(f(r0, theta0), theta0)/r0
assert trigsimp(df(R2.e_y)(p_p).doit()) == sin(theta0)*Derivative(f(r0, theta0), r0) + cos(theta0)*Derivative(f(r0, theta0), theta0)/r0
assert R2.dx(R2.e_x)(p_r) == 1
assert R2.dx(R2.e_y)(p_r) == 0
circ = -R2.y*R2.e_x + R2.x*R2.e_y
assert R2.dx(circ)(p_r).doit() == -y0
assert R2.dy(circ)(p_r) == x0
assert R2.dr(circ)(p_r) == 0
assert simplify(R2.dtheta(circ)(p_r)) == 1
assert (circ - R2.e_theta)(s_field_r)(p_r) == 0
开发者ID:aeberspaecher,项目名称:sympy,代码行数:34,代码来源:test_function_diffgeom_book.py
示例20: test_sympy_parser
def test_sympy_parser():
x = Symbol('x')
inputs = {
'2*x': 2 * x,
'3.00': Float(3),
'22/7': Rational(22, 7),
'2+3j': 2 + 3*I,
'exp(x)': exp(x),
'x!': factorial(x),
'x!!': factorial2(x),
'(x + 1)! - 1': factorial(x + 1) - 1,
'3.[3]': Rational(10, 3),
'.0[3]': Rational(1, 30),
'3.2[3]': Rational(97, 30),
'1.3[12]': Rational(433, 330),
'1 + 3.[3]': Rational(13, 3),
'1 + .0[3]': Rational(31, 30),
'1 + 3.2[3]': Rational(127, 30),
'.[0011]': Rational(1, 909),
'0.1[00102] + 1': Rational(366697, 333330),
'1.[0191]': Rational(10190, 9999),
'10!': 3628800,
'-(2)': -Integer(2),
'[-1, -2, 3]': [Integer(-1), Integer(-2), Integer(3)],
'Symbol("x").free_symbols': x.free_symbols,
"S('S(3).n(n=3)')": 3.00,
'factorint(12, visual=True)': Mul(
Pow(2, 2, evaluate=False),
Pow(3, 1, evaluate=False),
evaluate=False),
'Limit(sin(x), x, 0, dir="-")': Limit(sin(x), x, 0, dir='-'),
}
for text, result in inputs.items():
assert parse_expr(text) == result
开发者ID:Lenqth,项目名称:sympy,代码行数:35,代码来源:test_sympy_parser.py
注:本文中的sympy.functions.sin函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论