本文整理汇总了Python中sympy.Function.diff方法的典型用法代码示例。如果您正苦于以下问题:Python Function.diff方法的具体用法?Python Function.diff怎么用?Python Function.diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Function
的用法示例。
在下文中一共展示了Function.diff方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_latex_printer
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
def test_latex_printer():
r = Function('r')('t')
assert VectorLatexPrinter().doprint(r ** 2) == "r^{2}"
r2 = Function('r^2')('t')
assert VectorLatexPrinter().doprint(r2.diff()) == r'\dot{r^{2}}'
ra = Function('r__a')('t')
assert VectorLatexPrinter().doprint(ra.diff().diff()) == r'\ddot{r^{a}}'
示例2: test_simple
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
def test_simple():
sympy.var('x, y, r')
u = Function('u')(x, y)
w = Function('w')(x, y)
f = Function('f')(x, y)
e = (u.diff(x) + 1./2*w.diff(x,x)**2)*f.diff(x,y) \
+ w.diff(x,y)*f.diff(x,x)
return Vexpr(e, u, w)
示例3: idiff
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
def idiff(eq, y, x, n=1):
"""Return ``dy/dx`` assuming that ``eq == 0``.
Parameters
==========
y : the dependent variable or a list of dependent variables (with y first)
x : the variable that the derivative is being taken with respect to
n : the order of the derivative (default is 1)
Examples
========
>>> from sympy.abc import x, y, a
>>> from sympy.geometry.util import idiff
>>> circ = x**2 + y**2 - 4
>>> idiff(circ, y, x)
-x/y
>>> idiff(circ, y, x, 2).simplify()
-(x**2 + y**2)/y**3
Here, ``a`` is assumed to be independent of ``x``:
>>> idiff(x + a + y, y, x)
-1
Now the x-dependence of ``a`` is made explicit by listing ``a`` after
``y`` in a list.
>>> idiff(x + a + y, [y, a], x)
-Derivative(a, x) - 1
See Also
========
sympy.core.function.Derivative: represents unevaluated derivatives
sympy.core.function.diff: explicitly differentiates wrt symbols
"""
if is_sequence(y):
dep = set(y)
y = y[0]
elif isinstance(y, Symbol):
dep = set([y])
else:
raise ValueError("expecting x-dependent symbol(s) but got: %s" % y)
f = dict([(s, Function(
s.name)(x)) for s in eq.atoms(Symbol) if s != x and s in dep])
dydx = Function(y.name)(x).diff(x)
eq = eq.subs(f)
derivs = {}
for i in range(n):
yp = solve(eq.diff(x), dydx)[0].subs(derivs)
if i == n - 1:
return yp.subs([(v, k) for k, v in f.items()])
derivs[dydx] = yp
eq = dydx - yp
dydx = dydx.diff(x)
示例4: test_noncommutative_issue_15131
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
def test_noncommutative_issue_15131():
x = Symbol('x', commutative=False)
t = Symbol('t', commutative=False)
fx = Function('Fx', commutative=False)(x)
ft = Function('Ft', commutative=False)(t)
A = Symbol('A', commutative=False)
eq = fx * A * ft
eqdt = eq.diff(t)
assert eqdt.args[-1] == ft.diff(t)
示例5: test_lambdify_Derivative_arg_issue_16468
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
def test_lambdify_Derivative_arg_issue_16468():
f = Function('f')(x)
fx = f.diff()
assert lambdify((f, fx), f + fx)(10, 5) == 15
assert eval(lambdastr((f, fx), f/fx))(10, 5) == 2
raises(SyntaxError, lambda:
eval(lambdastr((f, fx), f/fx, dummify=False)))
assert eval(lambdastr((f, fx), f/fx, dummify=True))(10, 5) == 2
assert eval(lambdastr((fx, f), f/fx, dummify=True))(10, 5) == S.Half
assert lambdify(fx, 1 + fx)(41) == 42
assert eval(lambdastr(fx, 1 + fx, dummify=True))(41) == 42
示例6: test_solve_for_functions_derivatives
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
def test_solve_for_functions_derivatives():
t = Symbol('t')
x = Function('x')(t)
y = Function('y')(t)
a11,a12,a21,a22,b1,b2 = symbols('a11,a12,a21,a22,b1,b2')
soln = solve([a11*x + a12*y - b1, a21*x + a22*y - b2], x, y)
assert soln == {
x : (a22*b1 - a12*b2)/(a11*a22 - a12*a21),
y : (a11*b2 - a21*b1)/(a11*a22 - a12*a21),
}
assert solve(x - 1, x) == [1]
assert solve(3*x - 2, x) == [Rational(2, 3)]
soln = solve([a11*x.diff(t) + a12*y.diff(t) - b1, a21*x.diff(t) +
a22*y.diff(t) - b2], x.diff(t), y.diff(t))
assert soln == { y.diff(t) : (a11*b2 - a21*b1)/(a11*a22 - a12*a21),
x.diff(t) : (a22*b1 - a12*b2)/(a11*a22 - a12*a21) }
assert solve(x.diff(t)-1, x.diff(t)) == [1]
assert solve(3*x.diff(t)-2, x.diff(t)) == [Rational(2,3)]
eqns = set((3*x - 1, 2*y-4))
assert solve(eqns, set((x,y))) == { x : Rational(1, 3), y: 2 }
x = Symbol('x')
f = Function('f')
F = x**2 + f(x)**2 - 4*x - 1
assert solve(F.diff(x), diff(f(x), x)) == [-((x - 2)/f(x))]
# Mixed cased with a Symbol and a Function
x = Symbol('x')
y = Function('y')(t)
soln = solve([a11*x + a12*y.diff(t) - b1, a21*x +
a22*y.diff(t) - b2], x, y.diff(t))
assert soln == { y.diff(t) : (a11*b2 - a21*b1)/(a11*a22 - a12*a21),
x : (a22*b1 - a12*b2)/(a11*a22 - a12*a21) }
示例7: _test_f
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
def _test_f():
# FIXME: we get infinite recursion here:
f = Function("f")
assert residue(f(x)/x**5, x, 0) == f.diff(x, 4)/24
示例8: test_cylinder_clpt
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
def test_cylinder_clpt():
'''Test case where the functional corresponds to the internal energy of
a cylinder using the Classical Laminated Plate Theory (CLPT)
'''
from sympy import Matrix
sympy.var('x, y, r')
sympy.var('B11, B12, B16, B21, B22, B26, B61, B62, B66')
sympy.var('D11, D12, D16, D21, D22, D26, D61, D62, D66')
# displacement field
u = Function('u')(x, y)
v = Function('v')(x, y)
w = Function('w')(x, y)
# stress function
f = Function('f')(x, y)
# laminate constitute matrices B represents B*, see Jones (1999)
B = Matrix([[B11, B12, B16],
[B21, B22, B26],
[B61, B62, B66]])
# D represents D*, see Jones (1999)
D = Matrix([[D11, D12, D16],
[D12, D22, D26],
[D16, D26, D66]])
# strain-diplacement equations
e = Matrix([[u.diff(x) + 1./2*w.diff(x)**2],
[v.diff(y) + 1./r*w + 1./2*w.diff(y)**2],
[u.diff(y) + v.diff(x) + w.diff(x)*w.diff(y)]])
k = Matrix([[ -w.diff(x, x)],
[ -w.diff(y, y)],
[-2*w.diff(x, y)]])
# representing the internal forces using the stress function
N = Matrix([[ f.diff(y, y)],
[ f.diff(x, x)],
[ -f.diff(x, y)]])
functional = N.T*V(e) - N.T*B*V(k) + k.T*D.T*V(k)
return Vexpr(functional, u, v, w)
示例9: pprint
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
pprint(eq2(u(x, y), v(x, y)))
print "\nSolution:"
u_hat = 1 - (exp(k*x)+exp(-k*x)) / (exp(k)+exp(-k))
pprint(Eq(Function("u_hat")(x), u_hat))
#test the Boundary Conditions:
assert u_hat.subs(x, -1) == 0
assert u_hat.subs(x, 1) == 0
u = cos(x*pi/2)*cos(y*pi/2)
v = u_hat*u_hat.subs(x, y)
print "u:"
pprint(u)
print "u:", ccode(u)
print "d u/d x:", ccode(u.diff(x))
print "d u/d y:", ccode(u.diff(y))
print "v:"
pprint(v)
print "v:", ccode(v)
print "d v/d x:", ccode(v.diff(x))
print "d v/d y:", ccode(v.diff(y))
print "-"*80
print "RHS, for f(u)=u:"
# delete this redefinition to get nonlinear f(u):
def f(u):
return u
e1 = eq1(u, v, f)
e2 = eq2(u, v)
print "g1:"
示例10: symbols
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
from sympy import Function, Symbol, symbols, Derivative, preview, simplify, collect, Wild
from sympy import diff, ln, sin, pprint, sqrt, latex, Integral
import sympy as sym
x, y, z, t = symbols('x y z t')
f = Function('f')
F = Function('F')(x, y, z)
g = Function('g', real=True)(ln(F))
result = diff(sin(x), x)
print(result)
print(f(x * x).diff(x))
print(g.diff(x))
aaa = g.diff(x, 2)
# aaa._args[1] * aaa._args[0]
# init_printing()
pprint(Integral(sqrt(1 / x), x), use_unicode=True)
print(latex(Integral(sqrt(1 / x), x)))
print("\n\n")
pprint(g.diff((x, 1), (y, 0)), use_unicode=True)
# pprint(g.diff((x, 2),(y, 2)), use_unicode=True)
pprint(sym.diff(sym.tan(x), x))
pprint(sym.diff(g, x))
print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
from sympy import Derivative as D, collect, Function
示例11: latex
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
g3=g3.subs(sin(phi)**2, 1-cos(phi)**2).expand().simplify()
print r'%\alpha^{2} + \beta^{2} + \gamma^{2} = ', latex(g3)
x_hat = Matrix([
rho * sin(theta) * cos(phi),
rho * sin(theta) * sin(phi),
rho * cos(theta)])
psi = Function("psi")
psi =exp(I*omega*t) * exp(-I*g2)
print "\Psi =", latex(psi)
#Derivatives of the wave function of the coordinates
dpsidx=psi.diff(x)
dpsidx=dpsidx.subs(psi,'Psi').expand().simplify()
print "d \Psi / dx =", latex(dpsidx)
dpsidy=psi.diff(y)
dpsidy=dpsidy.subs(psi,'Psi').expand().simplify()
print "d \Psi / dy =", latex(dpsidy)
dpsidz=psi.diff(z)
dpsidz=dpsidz.subs(psi,'Psi').expand().simplify()
print "d \Psi / dz =", latex(dpsidz)
########### Maxwell's Equations ###################
#A,B,C1,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R = symbols('A B C1 D E F G H I J K L M N O P Q R', cls=Function)
omega, mu, epsilon, muz, epsilonz = symbols('omega mu epsilon mu_z epsilon_z', integer=True)
# Vertical indexs: Hx Hy Hz Ex Ey Ez
示例12: Function
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
#u3p = Function("u3p")(t)
#u4p = Function("u4p")(t)
#u5p = Function("u5p")(t)
P_NC_CO = r2*A[3] - r1*B[3]
#print "P_NC_CO> = ", P_NC_CO
P_NO_CO = q1*N[1] + q2*N[2] + P_NC_CO
V_CN_N = au1*A[1] + au2*A[2] + au3*A[3]
#print "V_CN_N> = ", V_CN_N
V_CO_N = V_CN_N + cross(C.get_omega(N), P_NC_CO)
#print "V_CO_N> = ", V_CO_N
qdots = [q3.diff(t), q4.diff(t), q5.diff(t), au1, au2, au3, u3.diff(t), \
u4.diff(t), u5.diff(t)]
us = [u3, u4, u5, au1, au2, au3, u3p, u4p, u5p]
gen_speeds = dict(zip(qdots, us))
C.set_omega(C.get_omega(N).subs(gen_speeds), N, force = True)
V_CO_N = V_CO_N.subs(gen_speeds)
V_CN_N = V_CN_N.subs(gen_speeds)
WC = coeff(C.get_omega(N), us[:-3])
VC = coeff(V_CO_N, us[:-3])
VCN = coeff(V_CN_N, us[:-3])
#print WC
示例13: Function
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
@author: Topher
"""
from __future__ import division
import sympy as sp
from sympy import sin,cos,Function
t = sp.Symbol('t')
params = sp.symbols('M , G , J , J_ball , R')
M , G , J , J_ball , R = params
# ball position r
r_t = Function('r')(t)
d_r_t = r_t.diff(t)
dd_r_t = r_t.diff(t,2)
# beam angle theta
theta_t = Function('theta')(t)
d_theta_t = theta_t.diff(t)
dd_theta_t = theta_t.diff(t,2)
# torque of the beam
tau = Function('tau')
# kinetic energy
T = ((M + J_ball/R**2)*d_r_t**2 + (J + M*r_t**2 + J_ball)*d_theta_t**2)/2
# potential energy
V = M*G*r_t*sin(theta_t)
# lagrange function
示例14: asin
# 需要导入模块: from sympy import Function [as 别名]
# 或者: from sympy.Function import diff [as 别名]
q9 = asin(dot(H[1], A[2])) # Front wheel yaw relative to rear wheel yaw
q10 = asin(dot(E[2], N[3])) # Front assembly lean
front_pitch = asin(-dot(E[1], g3)) # Front assembly pitch
"""
# Expressions for E[1] and E[3] measure numbers of g3
g31_expr = dot(g3, E[1])
g33_expr = dot(g3, E[3])
num1 = g3_num.dict[E[1]]
num2 = g3_num.dict[E[3]]
den = g3_den
# Time derivatives of expressions for E[1] and E[3] measure numbers of g3
g31_expr_dt = (num1.diff(t)*den - num1*den.diff(t))/den**2
g33_expr_dt = (num2.diff(t)*den - num2*den.diff(t))/den**2
g3_dict = {g31: g31_expr, g33: g33_expr, g31.diff(t): g31_expr_dt,
g33.diff(t): g33_expr_dt}
g3_symbol_dict = {g31: g31_s, g33: g33_s, g31.diff(t): g31d_s, g33.diff(t):
g33d_s}
# Position vector from front wheel center to front wheel contact point
# g31 and g33 are Sympy Functions which are 'unknown' functions of time.
fo_fn = Vector({E[1]: rf*g31, E[3]: rf*g33, N[3]: rft})
# Locate rear wheel center
CO = N.O.locate('CO', -rrt*N[3] -rr*B[3], C)
# Locate mass center of rear assembly (rear wheel, rear frame and rider)
CDO = CO.locate('CDO', l1*D[1] + l2*D[3], D, mass=mcd)
# Locate top of steer axis
DE = CO.locate('DE', lr*D[1], D)
# Locate front wheel center