本文整理汇总了Python中sympy.tan函数的典型用法代码示例。如果您正苦于以下问题:Python tan函数的具体用法?Python tan怎么用?Python tan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tan函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_minimum
def test_minimum():
x, y = symbols('x y')
assert minimum(sin(x), x) == -S.One
assert minimum(sin(x), x, Interval(1, 4)) == sin(4)
assert minimum(tan(x), x) == -oo
assert minimum(tan(x), x, Interval(-pi/4, pi/4)) == -S.One
assert minimum(sin(x)*cos(x), x, S.Reals) == -S.Half
assert simplify(minimum(sin(x)*cos(x), x, Interval(3*pi/8, 5*pi/8))
) == -sqrt(2)/4
assert minimum((x+3)*(x-2), x) == -S(25)/4
assert minimum((x+3)/(x-2), x, Interval(-5, 0)) == -S(3)/2
assert minimum(x**4-x**3+x**2+10, x) == S(10)
assert minimum(exp(x), x, Interval(-2, oo)) == exp(-2)
assert minimum(log(x) - x, x, S.Reals) == -oo
assert minimum(cos(x), x, Union(Interval(0, 5), Interval(-6, -3))
) == -S.One
assert minimum(cos(x)-sin(x), x, S.Reals) == -sqrt(2)
assert minimum(y, x, S.Reals) == y
raises(ValueError, lambda : minimum(sin(x), x, S.EmptySet))
raises(ValueError, lambda : minimum(log(cos(x)), x, S.EmptySet))
raises(ValueError, lambda : minimum(1/(x**2 + y**2 + 1), x, S.EmptySet))
raises(ValueError, lambda : minimum(sin(x), sin(x)))
raises(ValueError, lambda : minimum(sin(x), x*y, S.EmptySet))
raises(ValueError, lambda : minimum(sin(x), S(1)))
示例2: test_ImageSet_simplification
def test_ImageSet_simplification():
from sympy.abc import n, m
assert imageset(Lambda(n, n), S.Integers) == S.Integers
assert imageset(Lambda(n, sin(n)), imageset(Lambda(m, tan(m)), S.Integers)) == imageset(
Lambda(m, sin(tan(m))), S.Integers
)
示例3: test_maximum
def test_maximum():
x, y = symbols('x y')
assert maximum(sin(x), x) == S.One
assert maximum(sin(x), x, Interval(0, 1)) == sin(1)
assert maximum(tan(x), x) == oo
assert maximum(tan(x), x, Interval(-pi/4, pi/4)) == S.One
assert maximum(sin(x)*cos(x), x, S.Reals) == S.Half
assert simplify(maximum(sin(x)*cos(x), x, Interval(3*pi/8, 5*pi/8))
) == sqrt(2)/4
assert maximum((x+3)*(x-2), x) == oo
assert maximum((x+3)*(x-2), x, Interval(-5, 0)) == S(14)
assert maximum((x+3)/(x-2), x, Interval(-5, 0)) == S(2)/7
assert simplify(maximum(-x**4-x**3+x**2+10, x)
) == 41*sqrt(41)/512 + S(5419)/512
assert maximum(exp(x), x, Interval(-oo, 2)) == exp(2)
assert maximum(log(x) - x, x, S.Reals) == -S.One
assert maximum(cos(x), x, Union(Interval(0, 5), Interval(-6, -3))
) == S.One
assert maximum(cos(x)-sin(x), x, S.Reals) == sqrt(2)
assert maximum(y, x, S.Reals) == y
raises(ValueError, lambda : maximum(sin(x), x, S.EmptySet))
raises(ValueError, lambda : maximum(log(cos(x)), x, S.EmptySet))
raises(ValueError, lambda : maximum(1/(x**2 + y**2 + 1), x, S.EmptySet))
raises(ValueError, lambda : maximum(sin(x), sin(x)))
raises(ValueError, lambda : maximum(sin(x), x*y, S.EmptySet))
raises(ValueError, lambda : maximum(sin(x), S(1)))
示例4: test_function_range
def test_function_range():
x, y, a, b = symbols('x y a b')
assert function_range(sin(x), x, Interval(-pi/2, pi/2)
) == Interval(-1, 1)
assert function_range(sin(x), x, Interval(0, pi)
) == Interval(0, 1)
assert function_range(tan(x), x, Interval(0, pi)
) == Interval(-oo, oo)
assert function_range(tan(x), x, Interval(pi/2, pi)
) == Interval(-oo, 0)
assert function_range((x + 3)/(x - 2), x, Interval(-5, 5)
) == Union(Interval(-oo, 2/7), Interval(8/3, oo))
assert function_range(1/(x**2), x, Interval(-1, 1)
) == Interval(1, oo)
assert function_range(exp(x), x, Interval(-1, 1)
) == Interval(exp(-1), exp(1))
assert function_range(log(x) - x, x, S.Reals
) == Interval(-oo, -1)
assert function_range(sqrt(3*x - 1), x, Interval(0, 2)
) == Interval(0, sqrt(5))
assert function_range(x*(x - 1) - (x**2 - x), x, S.Reals
) == FiniteSet(0)
assert function_range(x*(x - 1) - (x**2 - x) + y, x, S.Reals
) == FiniteSet(y)
assert function_range(sin(x), x, Union(Interval(-5, -3), FiniteSet(4))
) == Union(Interval(-sin(3), 1), FiniteSet(sin(4)))
assert function_range(cos(x), x, Interval(-oo, -4)
) == Interval(-1, 1)
raises(NotImplementedError, lambda : function_range(
exp(x)*(sin(x) - cos(x))/2 - x, x, S.Reals))
raises(NotImplementedError, lambda : function_range(
log(x), x, S.Integers))
raises(NotImplementedError, lambda : function_range(
sin(x)/2, x, S.Naturals))
示例5: test_tan_rewrite
def test_tan_rewrite():
x = Symbol('x')
neg_exp, pos_exp = exp(-x*I), exp(x*I)
assert tan(x).rewrite(exp) == I*(neg_exp-pos_exp)/(neg_exp+pos_exp)
assert tan(x).rewrite(sin) == 2*sin(x)**2/sin(2*x)
assert tan(x).rewrite(cos) == -cos(x + S.Pi/2)/cos(x)
assert tan(x).rewrite(cot) == 1/cot(x)
示例6: test_hyper_as_trig
def test_hyper_as_trig():
from sympy.simplify.fu import _osborne as o, _osbornei as i, TR12
eq = sinh(x)**2 + cosh(x)**2
t, f = hyper_as_trig(eq)
assert f(fu(t)) == cosh(2*x)
e, f = hyper_as_trig(tanh(x + y))
assert f(TR12(e)) == (tanh(x) + tanh(y))/(tanh(x)*tanh(y) + 1)
d = Dummy()
assert o(sinh(x), d) == I*sin(x*d)
assert o(tanh(x), d) == I*tan(x*d)
assert o(coth(x), d) == cot(x*d)/I
assert o(cosh(x), d) == cos(x*d)
for func in (sinh, cosh, tanh, coth):
h = func(pi)
assert i(o(h, d), d) == h
# /!\ the _osborne functions are not meant to work
# in the o(i(trig, d), d) direction so we just check
# that they work as they are supposed to work
assert i(cos(x*y), y) == cosh(x)
assert i(sin(x*y), y) == sinh(x)/I
assert i(tan(x*y), y) == tanh(x)/I
assert i(cot(x*y), y) == coth(x)*I
assert i(sec(x*y), y) == 1/cosh(x)
assert i(csc(x*y), y) == I/sinh(x)
示例7: trig_rule
def trig_rule(integral):
integrand, symbol = integral
if isinstance(integrand, sympy.sin) or isinstance(integrand, sympy.cos):
arg = integrand.args[0]
if not isinstance(arg, sympy.Symbol):
return # perhaps a substitution can deal with it
if isinstance(integrand, sympy.sin):
func = 'sin'
else:
func = 'cos'
return TrigRule(func, arg, integrand, symbol)
if isinstance(integrand, sympy.tan):
rewritten = sympy.sin(*integrand.args) / sympy.cos(*integrand.args)
elif isinstance(integrand, sympy.cot):
rewritten = sympy.cos(*integrand.args) / sympy.sin(*integrand.args)
elif isinstance(integrand, sympy.sec):
arg = integrand.args[0]
rewritten = ((sympy.sec(arg)**2 + sympy.tan(arg) * sympy.sec(arg)) /
(sympy.sec(arg) + sympy.tan(arg)))
elif isinstance(integrand, sympy.csc):
arg = integrand.args[0]
rewritten = ((sympy.csc(arg)**2 + sympy.cot(arg) * sympy.csc(arg)) /
(sympy.csc(arg) + sympy.cot(arg)))
return RewriteRule(
rewritten,
integral_steps(rewritten, symbol),
integrand, symbol
)
示例8: test_heurisch_trigonometric
def test_heurisch_trigonometric():
assert heurisch(sin(x), x) == -cos(x)
assert heurisch(pi*sin(x) + 1, x) == x - pi*cos(x)
assert heurisch(cos(x), x) == sin(x)
assert heurisch(tan(x), x) in [
log(1 + tan(x)**2)/2,
log(tan(x) + I) + I*x,
log(tan(x) - I) - I*x,
]
assert heurisch(sin(x)*sin(y), x) == -cos(x)*sin(y)
assert heurisch(sin(x)*sin(y), y) == -cos(y)*sin(x)
# gives sin(x) in answer when run via setup.py and cos(x) when run via py.test
assert heurisch(sin(x)*cos(x), x) in [sin(x)**2 / 2, -cos(x)**2 / 2]
assert heurisch(cos(x)/sin(x), x) == log(sin(x))
assert heurisch(x*sin(7*x), x) == sin(7*x) / 49 - x*cos(7*x) / 7
assert heurisch(1/pi/4 * x**2*cos(x), x) == 1/pi/4*(x**2*sin(x) -
2*sin(x) + 2*x*cos(x))
assert heurisch(acos(x/4) * asin(x/4), x) == 2*x - (sqrt(16 - x**2))*asin(x/4) \
+ (sqrt(16 - x**2))*acos(x/4) + x*asin(x/4)*acos(x/4)
assert heurisch(sin(x)/(cos(x)**2+1), x) == -atan(cos(x)) #fixes issue 13723
assert heurisch(1/(cos(x)+2), x) == 2*sqrt(3)*atan(sqrt(3)*tan(x/2)/3)/3
assert heurisch(2*sin(x)*cos(x)/(sin(x)**4 + 1), x) == atan(sqrt(2)*sin(x)
- 1) - atan(sqrt(2)*sin(x) + 1)
assert heurisch(1/cosh(x), x) == 2*atan(tanh(x/2))
示例9: test_evalc
def test_evalc():
x = Symbol("x", real=True)
y = Symbol("y", real=True)
z = Symbol("z")
assert ((x+I*y)**2).expand(complex=True) == x**2+2*I*x*y - y**2
assert expand_complex(z**(2*I)) == I*im(z**(2*I)) + re(z**(2*I))
assert exp(I*x) != cos(x)+I*sin(x)
assert exp(I*x).expand(complex=True) == cos(x)+I*sin(x)
assert exp(I*x+y).expand(complex=True) == exp(y)*cos(x)+I*sin(x)*exp(y)
assert sin(I*x).expand(complex=True) == I * sinh(x)
assert sin(x+I*y).expand(complex=True) == sin(x)*cosh(y) + \
I * sinh(y) * cos(x)
assert cos(I*x).expand(complex=True) == cosh(x)
assert cos(x+I*y).expand(complex=True) == cos(x)*cosh(y) - \
I * sinh(y) * sin(x)
assert tan(I*x).expand(complex=True) == tanh(x) * I
assert tan(x+I*y).expand(complex=True) == \
((sin(x)*cos(x) + I*cosh(y)*sinh(y)) / (cos(x)**2 + sinh(y)**2)).expand()
assert sinh(I*x).expand(complex=True) == I * sin(x)
assert sinh(x+I*y).expand(complex=True) == sinh(x)*cos(y) + \
I * sin(y) * cosh(x)
assert cosh(I*x).expand(complex=True) == cos(x)
assert cosh(x+I*y).expand(complex=True) == cosh(x)*cos(y) + \
I * sin(y) * sinh(x)
assert tanh(I*x).expand(complex=True) == tan(x) * I
assert tanh(x+I*y).expand(complex=True) == \
((sinh(x)*cosh(x) + I*cos(y)*sin(y)) / (sinh(x)**2 + cos(y)**2)).expand()
示例10: test_periodicity
def test_periodicity():
x = Symbol('x')
y = Symbol('y')
assert periodicity(sin(2*x), x) == pi
assert periodicity((-2)*tan(4*x), x) == pi/4
assert periodicity(sin(x)**2, x) == 2*pi
assert periodicity(3**tan(3*x), x) == pi/3
assert periodicity(tan(x)*cos(x), x) == 2*pi
assert periodicity(sin(x)**(tan(x)), x) == 2*pi
assert periodicity(tan(x)*sec(x), x) == 2*pi
assert periodicity(sin(2*x)*cos(2*x) - y, x) == pi/2
assert periodicity(tan(x) + cot(x), x) == pi
assert periodicity(sin(x) - cos(2*x), x) == 2*pi
assert periodicity(sin(x) - 1, x) == 2*pi
assert periodicity(sin(4*x) + sin(x)*cos(x), x) == pi
assert periodicity(exp(sin(x)), x) == 2*pi
assert periodicity(log(cot(2*x)) - sin(cos(2*x)), x) == pi
assert periodicity(sin(2*x)*exp(tan(x) - csc(2*x)), x) == pi
assert periodicity(cos(sec(x) - csc(2*x)), x) == 2*pi
assert periodicity(tan(sin(2*x)), x) == pi
assert periodicity(2*tan(x)**2, x) == pi
assert periodicity(sin(x)**2 + cos(x)**2, x) == S.Zero
assert periodicity(tan(x), y) == S.Zero
assert periodicity(exp(x), x) is None
assert periodicity(log(x), x) is None
assert periodicity(exp(x)**sin(x), x) is None
assert periodicity(sin(x)**y, y) is None
示例11: __init__
def __init__(self, dt, wheelbase):
EKF.__init__(self, 3, 2, 2)
self.dt = dt
self.wheelbase = wheelbase
a, x, y, v, w, theta, time = symbols(
'a, x, y, v, w, theta, t')
d = v*time
beta = (d/w)*sympy.tan(a)
r = w/sympy.tan(a)
self.fxu = Matrix([[x-r*sympy.sin(theta)+r*sympy.sin(theta+beta)],
[y+r*sympy.cos(theta)-r*sympy.cos(theta+beta)],
[theta+beta]])
self.F_j = self.fxu.jacobian(Matrix([x, y, theta]))
self.V_j = self.fxu.jacobian(Matrix([v, a]))
self.subs = {x: 0, y: 0, v:0, a:0, time:dt, w:wheelbase, theta:0}
self.x_x = x
self.x_y = y
self.v = v
self.a = a
self.theta = theta
示例12: test_tanh
def test_tanh():
x, y = symbols('xy')
k = Symbol('k', integer=True)
assert tanh(nan) == nan
assert tanh(oo) == 1
assert tanh(-oo) == -1
assert tanh(0) == 0
assert tanh(1) == tanh(1)
assert tanh(-1) == -tanh(1)
assert tanh(x) == tanh(x)
assert tanh(-x) == -tanh(x)
assert tanh(pi) == tanh(pi)
assert tanh(-pi) == -tanh(pi)
assert tanh(2**1024 * E) == tanh(2**1024 * E)
assert tanh(-2**1024 * E) == -tanh(2**1024 * E)
assert tanh(pi*I) == 0
assert tanh(-pi*I) == 0
assert tanh(2*pi*I) == 0
assert tanh(-2*pi*I) == 0
assert tanh(-3*10**73*pi*I) == 0
assert tanh(7*10**103*pi*I) == 0
assert tanh(pi*I/2) == tanh(pi*I/2)
assert tanh(-pi*I/2) == -tanh(pi*I/2)
assert tanh(5*pi*I/2) == tanh(5*pi*I/2)
assert tanh(7*pi*I/2) == tanh(7*pi*I/2)
assert tanh(pi*I/3) == sqrt(3)*I
assert tanh(-2*pi*I/3) == sqrt(3)*I
assert tanh(pi*I/4) == I
assert tanh(-pi*I/4) == -I
assert tanh(17*pi*I/4) == I
assert tanh(-3*pi*I/4) == I
assert tanh(pi*I/6) == I/sqrt(3)
assert tanh(-pi*I/6) == -I/sqrt(3)
assert tanh(7*pi*I/6) == I/sqrt(3)
assert tanh(-5*pi*I/6) == I/sqrt(3)
assert tanh(pi*I/105) == tan(pi/105)*I
assert tanh(-pi*I/105) == -tan(pi/105)*I
assert tanh(2 + 3*I) == tanh(2 + 3*I)
assert tanh(x*I) == tan(x)*I
assert tanh(k*pi*I) == 0
assert tanh(17*k*pi*I) == 0
assert tanh(k*pi*I/2) == tan(k*pi/2)*I
示例13: test_issue_2033
def test_issue_2033():
r, t = symbols("r,t")
assert solve([r - x ** 2 - y ** 2, tan(t) - y / x], [x, y]) == [
(-sqrt(r * sin(t) ** 2) / tan(t), -sqrt(r * sin(t) ** 2)),
(sqrt(r * sin(t) ** 2) / tan(t), sqrt(r * sin(t) ** 2)),
]
assert solve([exp(x) - sin(y), 1 / y - 3], [x, y]) == [(log(sin(S(1) / 3)), S(1) / 3)]
assert solve([exp(x) - sin(y), 1 / exp(y) - 3], [x, y]) == [(log(-sin(log(3))), -log(3))]
assert solve([exp(x) - sin(y), y ** 2 - 4], [x, y]) == [(log(-sin(2)), -2), (log(sin(2)), 2)]
eqs = [exp(x) ** 2 - sin(y) + z ** 2, 1 / exp(y) - 3]
assert solve(eqs) == [
{x: log(-sqrt(-z ** 2 - sin(log(3)))), y: -log(3)},
{x: log(sqrt(-z ** 2 - sin(log(3)))), y: -log(3)},
]
assert solve(eqs, x, z) == [{x: log(-sqrt(-z ** 2 + sin(y)))}, {x: log(sqrt(-z ** 2 + sin(y)))}]
assert solve(eqs, x, y) == [
(log(-sqrt(-z ** 2 - sin(log(3)))), -log(3)),
(log(sqrt(-z ** 2 - sin(log(3)))), -log(3)),
]
assert solve(eqs, y, z) == [(-log(3), -sqrt(-exp(2 * x) - sin(log(3)))), (-log(3), sqrt(-exp(2 * x) - sin(log(3))))]
eqs = [exp(x) ** 2 - sin(y) + z, 1 / exp(y) - 3]
assert solve(eqs) == [{x: log(-sqrt(-z - sin(log(3)))), y: -log(3)}, {x: log(sqrt(-z - sin(log(3)))), y: -log(3)}]
assert solve(eqs, x, z) == [{x: log(-sqrt(-z + sin(y)))}, {x: log(sqrt(-z + sin(y)))}]
assert solve(eqs, x, y) == [(log(-sqrt(-z - sin(log(3)))), -log(3)), (log(sqrt(-z - sin(log(3)))), -log(3))]
assert solve(eqs, z, y) == [(-exp(2 * x) - sin(log(3)), -log(3))]
assert solve((sqrt(x ** 2 + y ** 2) - sqrt(10), x + y - 4)) == [{x: 1, y: 3}, {x: 3, y: 1}]
assert solve((sqrt(x ** 2 + y ** 2) - sqrt(10), x + y - 4), x, y) == [(1, 3), (3, 1)]
示例14: newton
def newton():
x1 = Symbol("x1")
y1 = Symbol("y1")
m = 0.2
a = 0.7
e = 0.0001
f1 = tan(x1 * y1 + m) - x1
f2 = a * x1 ** 2 + 2 * y1 ** 2 - 1
y11 = diff(f1, x1)
y12 = diff(f1, y1)
y21 = diff(f2, x1)
y22 = diff(f2, y1)
j = Matrix([[y11, y12], [y21, y22]])
j1 = j.inv()
x0 = 0.75
y0 = 0.4
xn = x0 - j1[0, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0)
- j1[0, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)
yn = y0 - j1[1, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0)
- j1[1, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)
count2 = 0
while (abs(xn - x0) > e) or (abs(yn - y0) > e):
x0 = xn
y0 = yn
calcul = j1[0, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0) - j1[0, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)
xn = x0 - calcul
yn = y0 - j1[1, 0].subs(x1, x0).subs(y1, y0) * f1.subs(x1, x0).subs(y1, y0) - j1[1, 1].subs(x1, x0).subs(y1, y0) * f2.subs(x1, x0).subs(y1, y0)
count2 += 1
print("x = ", xn, " ", "y = ", yn, " - ", count2, " iterations")
print("graph processing...")
plot_implicit(Or(Eq(a * x1 ** 2 + 2 * y1 ** 2, 1), Eq(tan(x1 * y1 + m) - x1, 0)), (x1, -5, 5), (y1, -5, 5))
示例15: sp_derive
def sp_derive():
import sympy as sp
vars = 'G_s, s_n, s_p_n, w_n, dw_n, ds_n, G_s, G_w, c, phi'
syms = sp.symbols(vars)
for var, sym in zip(vars.split(','), syms):
globals()[var.strip()] = sym
s_n1 = s_n + ds_n
w_n1 = w_n + dw_n
tau_trial = G_s * (s_n1 - s_p_n)
print 'diff', sp.diff(tau_trial, ds_n)
print tau_trial
sig_n1 = G_w * w_n1
print sig_n1
tau_fr = (c + sig_n1 * sp.tan(phi)) * sp.Heaviside(sig_n1 - c / sp.tan(phi))
print tau_fr
d_tau_fr = sp.diff(tau_fr, dw_n)
print d_tau_fr
f_trial = sp.abs(tau_trial) - tau_fr
print f_trial
d_gamma = f_trial / G_s
print 'd_gamma'
sp.pretty_print(d_gamma)
print 'd_gamma_s'
sp.pretty_print(sp.diff(d_gamma, ds_n))
print 'tau_n1'
tau_n1 = sp.simplify(tau_trial - d_gamma * G_s * sp.sign(tau_trial))
sp.pretty_print(tau_n1)
print 'dtau_n1_w'
dtau_n1_w = sp.diff(tau_n1, dw_n)
sp.pretty_print(dtau_n1_w)
print 'dtau_n1_s'
dtau_n1_s = sp.diff(d_gamma * sp.sign(tau_trial), ds_n)
print dtau_n1_s
s_p_n1 = s_p_n + d_gamma * sp.sign(tau_trial)
print s_p_n1