本文整理汇总了Python中sympy.cos函数的典型用法代码示例。如果您正苦于以下问题:Python cos函数的具体用法?Python cos怎么用?Python cos使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cos函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nfloat
def test_nfloat():
from sympy.core.basic import _aresame
from sympy.polys.rootoftools import rootof
x = Symbol("x")
eq = x**(S(4)/3) + 4*x**(S(1)/3)/3
assert _aresame(nfloat(eq), x**(S(4)/3) + (4.0/3)*x**(S(1)/3))
assert _aresame(nfloat(eq, exponent=True), x**(4.0/3) + (4.0/3)*x**(1.0/3))
eq = x**(S(4)/3) + 4*x**(x/3)/3
assert _aresame(nfloat(eq), x**(S(4)/3) + (4.0/3)*x**(x/3))
big = 12345678901234567890
# specify precision to match value used in nfloat
Float_big = Float(big, 15)
assert _aresame(nfloat(big), Float_big)
assert _aresame(nfloat(big*x), Float_big*x)
assert _aresame(nfloat(x**big, exponent=True), x**Float_big)
assert nfloat({x: sqrt(2)}) == {x: nfloat(sqrt(2))}
assert nfloat({sqrt(2): x}) == {sqrt(2): x}
assert nfloat(cos(x + sqrt(2))) == cos(x + nfloat(sqrt(2)))
# issue 6342
f = S('x*lamda + lamda**3*(x/2 + 1/2) + lamda**2 + 1/4')
assert not any(a.free_symbols for a in solveset(f.subs(x, -0.139)))
# issue 6632
assert nfloat(-100000*sqrt(2500000001) + 5000000001) == \
9.99999999800000e-11
# issue 7122
eq = cos(3*x**4 + y)*rootof(x**5 + 3*x**3 + 1, 0)
assert str(nfloat(eq, exponent=False, n=1)) == '-0.7*cos(3.0*x**4 + y)'
示例2: 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)
示例3: test_sincos_rewrite
def test_sincos_rewrite():
x = Symbol("x")
y = Symbol("y")
assert sin(pi/2-x) == cos(x)
assert sin(pi-x) == sin(x)
assert cos(pi/2-x) == sin(x)
assert cos(pi-x) == -cos(x)
示例4: test_cross_different_frames3
def test_cross_different_frames3():
assert cross(A[1], C[1]) == sin(q3)*C[2]
assert cross(A[1], C[2]) == -sin(q3)*C[1] + cos(q3)*C[3]
assert cross(A[1], C[3]) == -cos(q3)*C[2]
assert cross(C[1], A[1]) == -sin(q3)*C[2]
assert cross(C[2], A[1]) == sin(q3)*C[1] - cos(q3)*C[3]
assert cross(C[3], A[1]) == cos(q3)*C[2]
示例5: test_cross_method
def test_cross_method():
N = NewtonianReferenceFrame('N')
q, qd = N.declare_coords('q', 3)
q1, q2, q3 = q
A = N.rotate('A', 1, q1)
B = N.rotate('B', 2, q2)
C = N.rotate('C', 3, q3)
assert cross(N[1], N[1]) == Vector(0) == 0
assert cross(N[1], N[2]) == N[3]
assert N[1].cross(N[3]) == Vector({N[2]: -1})
assert N[2].cross(N[1]) == Vector({N[3]: -1})
assert N[2].cross(N[2]) == Vector(0)
assert N[2].cross(N[3]) == N[1]
assert N[3].cross(N[1]) == N[2]
assert N[3].cross(N[2]) == Vector({N[1]: -1})
assert N[3].cross(N[3]) == Vector(0)
assert N[1].cross(A[1]) == Vector(0)
assert N[1].cross(A[2]) == A[3]
assert N[1].cross(A[3]) == Vector(-A[2])
assert N[2].cross(A[1]) == Vector(-N[3])
assert N[2].cross(A[2]) == Vector(sin(q1)*N[1])
assert N[2].cross(A[3]) == Vector(cos(q1)*N[1])
assert N[1].cross(B[1]) == Vector(sin(q2)*N[2])
assert N[1].cross(B[2]) == N[3]
assert N[1].cross(B[3]) == Vector(-cos(q2)*N[2])
示例6: test_as_ordered_terms
def test_as_ordered_terms():
f, g = symbols("f,g", cls=Function)
assert x.as_ordered_terms() == [x]
assert (sin(x) ** 2 * cos(x) + sin(x) * cos(x) ** 2 + 1).as_ordered_terms() == [
sin(x) ** 2 * cos(x),
sin(x) * cos(x) ** 2,
1,
]
args = [f(1), f(2), f(3), f(1, 2, 3), g(1), g(2), g(3), g(1, 2, 3)]
expr = Add(*args)
assert expr.as_ordered_terms() == args
assert (1 + 4 * sqrt(3) * pi * x).as_ordered_terms() == [4 * pi * x * sqrt(3), 1]
assert (2 + 3 * I).as_ordered_terms() == [2, 3 * I]
assert (-2 + 3 * I).as_ordered_terms() == [-2, 3 * I]
assert (2 - 3 * I).as_ordered_terms() == [2, -3 * I]
assert (-2 - 3 * I).as_ordered_terms() == [-2, -3 * I]
assert (4 + 3 * I).as_ordered_terms() == [4, 3 * I]
assert (-4 + 3 * I).as_ordered_terms() == [-4, 3 * I]
assert (4 - 3 * I).as_ordered_terms() == [4, -3 * I]
assert (-4 - 3 * I).as_ordered_terms() == [-4, -3 * I]
f = x ** 2 * y ** 2 + x * y ** 4 + y + 2
assert f.as_ordered_terms(order="lex") == [x ** 2 * y ** 2, x * y ** 4, y, 2]
assert f.as_ordered_terms(order="grlex") == [x * y ** 4, x ** 2 * y ** 2, y, 2]
assert f.as_ordered_terms(order="rev-lex") == [2, y, x * y ** 4, x ** 2 * y ** 2]
assert f.as_ordered_terms(order="rev-grlex") == [2, y, x ** 2 * y ** 2, x * y ** 4]
示例7: plotgrid_and_save
def plotgrid_and_save(name):
tmp_file = TmpFileManager.tmp_file
x = Symbol('x')
y = Symbol('y')
z = Symbol('z')
p1 = plot(x)
p2 = plot_parametric((sin(x), cos(x)), (x, sin(x)), show=False)
p3 = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500, show=False)
p4 = plot3d_parametric_line(sin(x), cos(x), x, show=False)
# symmetric grid
p = PlotGrid(2, 2, p1, p2, p3, p4)
p.save(tmp_file('%s_grid1' % name))
p._backend.close()
# grid size greater than the number of subplots
p = PlotGrid(3, 4, p1, p2, p3, p4)
p.save(tmp_file('%s_grid2' % name))
p._backend.close()
p5 = plot(cos(x),(x, -pi, pi), show=False)
p5[0].line_color = lambda a: a
p6 = plot(Piecewise((1, x > 0), (0, True)), (x, -1, 1), show=False)
p7 = plot_contour((x**2 + y**2, (x, -5, 5), (y, -5, 5)), (x**3 + y**3, (x, -3, 3), (y, -3, 3)), show=False)
# unsymmetric grid (subplots in one line)
p = PlotGrid(1, 3, p5, p6, p7)
p.save(tmp_file('%s_grid3' % name))
p._backend.close()
示例8: test_matrices
def test_matrices():
M = Matrix(2, 2, lambda i, j: (i + j + 1)*sin((i + j + 1)*x))
assert integrate(M, x) == Matrix([
[-cos(x), -cos(2*x)],
[-cos(2*x), -cos(3*x)],
])
示例9: test_ode_solutions
def test_ode_solutions():
# only a few examples here, the rest will be tested in the actual dsolve tests
assert ode_renumber(constantsimp(C1*exp(2*x)+exp(x)*(C2+C3), x, 3), 'C', 1, 3) == \
ode_renumber(C1*exp(x)+C2*exp(2*x), 'C', 1, 2)
assert ode_renumber(constantsimp(Eq(f(x),I*C1*sinh(x/3) + C2*cosh(x/3)), x, 2),
'C', 1, 2) == ode_renumber(Eq(f(x), C1*sinh(x/3) + C2*cosh(x/3)), 'C', 1, 2)
assert ode_renumber(constantsimp(Eq(f(x),acos((-C1)/cos(x))), x, 1), 'C', 1, 1) == \
Eq(f(x),acos(C1/cos(x)))
assert ode_renumber(constantsimp(Eq(log(f(x)/C1) + 2*exp(x/f(x)), 0), x, 1),
'C', 1, 1) == Eq(log(C1*f(x)) + 2*exp(x/f(x)), 0)
assert ode_renumber(constantsimp(Eq(log(x*2**Rational(1,2)*(1/x)**Rational(1,2)*f(x)\
**Rational(1,2)/C1) + x**2/(2*f(x)**2), 0), x, 1), 'C', 1, 1) == \
Eq(log(C1*x*(1/x)**Rational(1,2)*f(x)**Rational(1,2)) + x**2/(2*f(x)**2), 0)
assert ode_renumber(constantsimp(Eq(-exp(-f(x)/x)*sin(f(x)/x)/2 + log(x/C1) - \
cos(f(x)/x)*exp(-f(x)/x)/2, 0), x, 1), 'C', 1, 1) == \
Eq(-exp(-f(x)/x)*sin(f(x)/x)/2 + log(C1*x) - cos(f(x)/x)*exp(-f(x)/x)/2, 0)
u2 = Symbol('u2')
_a = Symbol('_a')
assert ode_renumber(constantsimp(Eq(-Integral(-1/((1 - u2**2)**Rational(1,2)*u2), \
(u2, _a, x/f(x))) + log(f(x)/C1), 0), x, 1), 'C', 1, 1) == \
Eq(-Integral(-1/(u2*(1 - u2**2)**Rational(1,2)), (u2, _a, x/f(x))) + \
log(C1*f(x)), 0)
assert map(lambda i: ode_renumber(constantsimp(i, x, 1), 'C', 1, 1),
[Eq(f(x), (-C1*x + x**2)**Rational(1,2)), Eq(f(x), -(-C1*x +
x**2)**Rational(1,2))]) == [Eq(f(x), (C1*x + x**2)**Rational(1,2)),
Eq(f(x), -(C1*x + x**2)**Rational(1,2))]
示例10: arbitrary_point
def arbitrary_point(self, t=None):
""" Returns an arbitrary point on the Plane; varying `t` from 0 to 2*pi
will move the point in a circle of radius 1 about p1 of the Plane.
Examples
========
>>> from sympy.geometry.plane import Plane
>>> from sympy.abc import t
>>> p = Plane((0, 0, 0), (0, 0, 1), (0, 1, 0))
>>> p.arbitrary_point(t)
Point3D(0, cos(t), sin(t))
>>> _.distance(p.p1).simplify()
1
Returns
=======
Point3D
"""
from sympy import cos, sin
t = t or Dummy('t')
x, y, z = self.normal_vector
a, b, c = self.p1.args
if x == y == 0:
return Point3D(a + cos(t), b + sin(t), c)
elif x == z == 0:
return Point3D(a + cos(t), b, c + sin(t))
elif y == z == 0:
return Point3D(a, b + cos(t), c + sin(t))
m = Dummy()
p = self.projection(Point3D(self.p1.x + cos(t), self.p1.y + sin(t), 0)*m)
return p.xreplace({m: solve(p.distance(self.p1) - 1, m)[0]})
示例11: test_issue_8368
def test_issue_8368():
assert integrate(exp(-s*x)*cosh(x), (x, 0, oo)) == \
Piecewise(
( pi*Piecewise(
( -s/(pi*(-s**2 + 1)),
Abs(s**2) < 1),
( 1/(pi*s*(1 - 1/s**2)),
Abs(s**(-2)) < 1),
( meijerg(
((S(1)/2,), (0, 0)),
((0, S(1)/2), (0,)),
polar_lift(s)**2),
True)
),
And(
Abs(periodic_argument(polar_lift(s)**2, oo)) < pi,
cos(Abs(periodic_argument(polar_lift(s)**2, oo))/2)*sqrt(Abs(s**2)) - 1 > 0,
Ne(s**2, 1))
),
(
Integral(exp(-s*x)*cosh(x), (x, 0, oo)),
True))
assert integrate(exp(-s*x)*sinh(x), (x, 0, oo)) == \
Piecewise(
( -1/(s + 1)/2 - 1/(-s + 1)/2,
And(
Ne(1/s, 1),
Abs(periodic_argument(s, oo)) < pi/2,
Abs(periodic_argument(s, oo)) <= pi/2,
cos(Abs(periodic_argument(s, oo)))*Abs(s) - 1 > 0)),
( Integral(exp(-s*x)*sinh(x), (x, 0, oo)),
True))
示例12: test_tan_rewrite
def test_tan_rewrite():
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)
assert tan(sinh(x)).rewrite(
exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, sinh(3)).n()
assert tan(cosh(x)).rewrite(
exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, cosh(3)).n()
assert tan(tanh(x)).rewrite(
exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, tanh(3)).n()
assert tan(coth(x)).rewrite(
exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, coth(3)).n()
assert tan(sin(x)).rewrite(
exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, sin(3)).n()
assert tan(cos(x)).rewrite(
exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, cos(3)).n()
assert tan(tan(x)).rewrite(
exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, tan(3)).n()
assert tan(cot(x)).rewrite(
exp).subs(x, 3).n() == tan(x).rewrite(exp).subs(x, cot(3)).n()
assert tan(log(x)).rewrite(Pow) == I*(x**-I - x**I)/(x**-I + x**I)
assert 0 == (cos(pi/15)*tan(pi/15) - sin(pi/15)).rewrite(pow)
assert tan(pi/19).rewrite(pow) == tan(pi/19)
assert tan(8*pi/19).rewrite(sqrt) == tan(8*pi/19)
示例13: test_derivative_by_array
def test_derivative_by_array():
from sympy.abc import a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
bexpr = x*y**2*exp(z)*log(t)
sexpr = sin(bexpr)
cexpr = cos(bexpr)
a = Array([sexpr])
assert derive_by_array(sexpr, t) == x*y**2*exp(z)*cos(x*y**2*exp(z)*log(t))/t
assert derive_by_array(sexpr, [x, y, z]) == Array([bexpr/x*cexpr, 2*y*bexpr/y**2*cexpr, bexpr*cexpr])
assert derive_by_array(a, [x, y, z]) == Array([[bexpr/x*cexpr], [2*y*bexpr/y**2*cexpr], [bexpr*cexpr]])
assert derive_by_array(sexpr, [[x, y], [z, t]]) == Array([[bexpr/x*cexpr, 2*y*bexpr/y**2*cexpr], [bexpr*cexpr, bexpr/log(t)/t*cexpr]])
assert derive_by_array(a, [[x, y], [z, t]]) == Array([[[bexpr/x*cexpr], [2*y*bexpr/y**2*cexpr]], [[bexpr*cexpr], [bexpr/log(t)/t*cexpr]]])
assert derive_by_array([[x, y], [z, t]], [x, y]) == Array([[[1, 0], [0, 0]], [[0, 1], [0, 0]]])
assert derive_by_array([[x, y], [z, t]], [[x, y], [z, t]]) == Array([[[[1, 0], [0, 0]], [[0, 1], [0, 0]]],
[[[0, 0], [1, 0]], [[0, 0], [0, 1]]]])
assert diff(sexpr, t) == x*y**2*exp(z)*cos(x*y**2*exp(z)*log(t))/t
assert diff(sexpr, Array([x, y, z])) == Array([bexpr/x*cexpr, 2*y*bexpr/y**2*cexpr, bexpr*cexpr])
assert diff(a, Array([x, y, z])) == Array([[bexpr/x*cexpr], [2*y*bexpr/y**2*cexpr], [bexpr*cexpr]])
assert diff(sexpr, Array([[x, y], [z, t]])) == Array([[bexpr/x*cexpr, 2*y*bexpr/y**2*cexpr], [bexpr*cexpr, bexpr/log(t)/t*cexpr]])
assert diff(a, Array([[x, y], [z, t]])) == Array([[[bexpr/x*cexpr], [2*y*bexpr/y**2*cexpr]], [[bexpr*cexpr], [bexpr/log(t)/t*cexpr]]])
assert diff(Array([[x, y], [z, t]]), Array([x, y])) == Array([[[1, 0], [0, 0]], [[0, 1], [0, 0]]])
assert diff(Array([[x, y], [z, t]]), Array([[x, y], [z, t]])) == Array([[[[1, 0], [0, 0]], [[0, 1], [0, 0]]],
[[[0, 0], [1, 0]], [[0, 0], [0, 1]]]])
示例14: test_dyadic
def test_dyadic():
d1 = A.x | A.x
d2 = A.y | A.y
d3 = A.x | A.y
assert d1 * 0 == 0
assert d1 != 0
assert d1 * 2 == 2 * A.x | A.x
assert d1 / 2. == 0.5 * d1
assert d1 & (0 * d1) == 0
assert d1 & d2 == 0
assert d1 & A.x == A.x
assert d1 ^ A.x == 0
assert d1 ^ A.y == A.x | A.z
assert d1 ^ A.z == - A.x | A.y
assert d2 ^ A.x == - A.y | A.z
assert A.x ^ d1 == 0
assert A.y ^ d1 == - A.z | A.x
assert A.z ^ d1 == A.y | A.x
assert A.x & d1 == A.x
assert A.y & d1 == 0
assert A.y & d2 == A.y
assert d1 & d3 == A.x | A.y
assert d3 & d1 == 0
assert d1.dt(A) == 0
q = dynamicsymbols('q')
qd = dynamicsymbols('q', 1)
B = A.orientnew('B', 'Axis', [q, A.z])
assert d1.express(B) == d1.express(B, B)
assert d1.express(B) == ((cos(q)**2) * (B.x | B.x) + (-sin(q) * cos(q)) *
(B.x | B.y) + (-sin(q) * cos(q)) * (B.y | B.x) + (sin(q)**2) *
(B.y | B.y))
assert d1.express(B, A) == (cos(q)) * (B.x | A.x) + (-sin(q)) * (B.y | A.x)
assert d1.express(A, B) == (cos(q)) * (A.x | B.x) + (-sin(q)) * (A.x | B.y)
assert d1.dt(B) == (-qd) * (A.y | A.x) + (-qd) * (A.x | A.y)
示例15: test_solve_sqrt_3
def test_solve_sqrt_3():
R = Symbol("R")
eq = sqrt(2) * R * sqrt(1 / (R + 1)) + (R + 1) * (sqrt(2) * sqrt(1 / (R + 1)) - 1)
sol = solveset_complex(eq, R)
assert sol == FiniteSet(
*[
S(5) / 3 + 4 * sqrt(10) * cos(atan(3 * sqrt(111) / 251) / 3) / 3,
-sqrt(10) * cos(atan(3 * sqrt(111) / 251) / 3) / 3
+ 40 * re(1 / ((-S(1) / 2 - sqrt(3) * I / 2) * (S(251) / 27 + sqrt(111) * I / 9) ** (S(1) / 3))) / 9
+ sqrt(30) * sin(atan(3 * sqrt(111) / 251) / 3) / 3
+ S(5) / 3
+ I
* (
-sqrt(30) * cos(atan(3 * sqrt(111) / 251) / 3) / 3
- sqrt(10) * sin(atan(3 * sqrt(111) / 251) / 3) / 3
+ 40 * im(1 / ((-S(1) / 2 - sqrt(3) * I / 2) * (S(251) / 27 + sqrt(111) * I / 9) ** (S(1) / 3))) / 9
),
]
)
# the number of real roots will depend on the value of m: for m=1 there are 4
# and for m=-1 there are none.
eq = -sqrt((m - q) ** 2 + (-m / (2 * q) + S(1) / 2) ** 2) + sqrt(
(-m ** 2 / 2 - sqrt(4 * m ** 4 - 4 * m ** 2 + 8 * m + 1) / 4 - S(1) / 4) ** 2
+ (m ** 2 / 2 - m - sqrt(4 * m ** 4 - 4 * m ** 2 + 8 * m + 1) / 4 - S(1) / 4) ** 2
)
raises(NotImplementedError, lambda: solveset_real(eq, q))