• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sympy.Function类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.Function的典型用法代码示例。如果您正苦于以下问题:Python Function类的具体用法?Python Function怎么用?Python Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Function类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: idiff

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)
开发者ID:Krastanov,项目名称:sympy,代码行数:60,代码来源:util.py


示例2: _main

 def _main(expr):
     _new = []
     for a in expr.args:
         is_V = False
         if isinstance(a, V):
             is_V = True
             a = a.expr
         if a.is_Derivative:
             variables = a.atoms()
             func = a.expr
             variables.add(func)
             name = a.expr.__class__.__name__
             if ',' in name:
                 a = Function('%s' % name +
                       ''.join(map(str, a.variables)))(*variables)
             else:
                 a = Function('%s' % name + ',' +
                       ''.join(map(str, a.variables)))(*variables)
         #TODO add more, maybe all that have args
         elif a.is_Add or a.is_Mul or a.is_Pow:
             a = _main(a)
         if is_V:
             a = V(a)
             a.function = func
         _new.append( a )
     return expr.func(*tuple(_new))
开发者ID:saullocastro,项目名称:programming,代码行数:26,代码来源:voperator.py


示例3: test_latex_printer

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}}'
开发者ID:asmeurer,项目名称:sympy,代码行数:7,代码来源:test_printing.py


示例4: test_noncommutative_issue_15131

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)
开发者ID:cklb,项目名称:sympy,代码行数:9,代码来源:test_function.py


示例5: test_issue_7687

def test_issue_7687():
    from sympy.core.function import Function
    from sympy.abc import x
    f = Function('f')(x)
    ff = Function('f')(x)
    match_with_cache = ff.matches(f)
    assert isinstance(f, type(ff))
    clear_cache()
    ff = Function('f')(x)
    assert isinstance(f, type(ff))
    assert match_with_cache == ff.matches(f)
开发者ID:Lenqth,项目名称:sympy,代码行数:11,代码来源:test_function.py


示例6: test_lambdify_Derivative_arg_issue_16468

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
开发者ID:cmarqu,项目名称:sympy,代码行数:11,代码来源:test_lambdify.py


示例7: test_find_simple_recurrence

def test_find_simple_recurrence():
    a = Function('a')
    n = Symbol('n')
    assert find_simple_recurrence([fibonacci(k) for k in range(12)]) == (
        -a(n) - a(n + 1) + a(n + 2))

    f = Function('a')
    i = Symbol('n')
    a = [1, 1, 1]
    for k in range(15): a.append(5*a[-1]-3*a[-2]+8*a[-3])
    assert find_simple_recurrence(a, A=f, N=i) == (
        -8*f(i) + 3*f(i + 1) - 5*f(i + 2) + f(i + 3))
    assert find_simple_recurrence([0, 2, 15, 74, 12, 3, 0,
                                    1, 2, 85, 4, 5, 63]) == 0
开发者ID:A-turing-machine,项目名称:sympy,代码行数:14,代码来源:test_guess.py


示例8: test_simple

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)
开发者ID:saullocastro,项目名称:programming,代码行数:8,代码来源:voperator.py


示例9: test_solve_for_functions_derivatives

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) }
开发者ID:fxkr,项目名称:sympy,代码行数:38,代码来源:test_solvers.py


示例10: Function

Lagrange formalism

@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)
开发者ID:cklb,项目名称:pymoskito,代码行数:30,代码来源:lagrange.py


示例11: _test_f

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
开发者ID:AALEKH,项目名称:sympy,代码行数:4,代码来源:test_residues.py


示例12: open

import sys
import numpy as np
import sympy as sm
from sympy.solvers import solve
from sympy import Symbol, Function
import GUI as gui
import math
GCodeFile = open('C:\\3D Printer Calculus Project\\docs\\Sample.txt', 'w+')
x = Symbol('x')
f = Function('f')(x)
f = 0.5*x
xVals = []
yVals = []
zVals = []
SideArray = []
TotalVolume = 0
AxisChoice = gui.AxisRevScreen()
if AxisChoice == "X-axis":
	Bounds = gui.BoundsScreen()
	FirstBound = int(Bounds[0])
	FinalBound = int(Bounds[1])
	xInitialVal = FirstBound
	yInitialVal = f.subs(x, FirstBound)
	zInitialVal = 0
	xVals.append(xInitialVal)
	yVals.append(yInitialVal)
	zVals.append(zInitialVal)
	FinalBound1 = int(FinalBound * 10)
	FirstBound1 = int(FirstBound * 10)
	for t in range (FirstBound1, FinalBound1):
	### This for loop generates the x coordinates ###
开发者ID:vojha2409,项目名称:CalcPrintProj,代码行数:31,代码来源:Calculations.py


示例13: symbols

from numpy import array, arange
from sympy import symbols, Function, S, solve, simplify, \
        collect, Matrix, lambdify

from pydy import ReferenceFrame, cross, dot, dt, express, expression2vector, \
    coeff

m, g, r1, r2, t = symbols("m, g r1 r2 t")
au1, au2, au3 = symbols("au1 au2 au3")
cf1, cf2, cf3 = symbols("cf1 cf2 cf3")
I, J = symbols("I J")
u3p, u4p, u5p = symbols("u3p u4p u5p")

q1 = Function("q1")(t)
q2 = Function("q2")(t)
q3 = Function("q3")(t)
q4 = Function("q4")(t)
q5 = Function("q5")(t)

def eval(a):
    subs_dict = {
        u3.diff(t): u3p,
        u4.diff(t): u4p,
        u5.diff(t): u5p,
        r1:1,
        r2:0,
        m:1,
        g:1,
        I:1,
        J:1,
        }
开发者ID:certik,项目名称:pydy,代码行数:31,代码来源:spherical_pendulum.py


示例14: latex

print "r =", g2

#Propagation constants along the axes are related
g3 = alpha1**2 + beta1**2 + gamma1**2

# Simplifying
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()
开发者ID:Ignat99,项目名称:physical-formulas,代码行数:31,代码来源:formulas1.py


示例15: test_cylinder_clpt

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)
开发者ID:saullocastro,项目名称:programming,代码行数:38,代码来源:voperator.py


示例16: tan

        ICD11 ICD22 ICD33 ICD13 IEF11 IEF22 IEF33 IEF13 IF22 g')
# Declare coordinates and their time derivatives
q, qd = N.declare_coords('q', 11)
# Declare speeds and their time derivatives
u, ud = N.declare_speeds('u', 6)
# Unpack the lists
rr, rrt, rf, rft, lr, ls, lf, l1, l2, l3, l4, mcd, mef, IC22, ICD11, ICD22,\
        ICD33, ICD13, IEF11, IEF22, IEF33, IEF13, IF22, g = params
q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11 = q
q1d, q2d, q3d, q4d, q5d, q6d, q7d, q8d, q9d, q10d, q11d = qd
u1, u2, u3, u4, u5, u6 = u
u1d, u2d, u3d, u4d, u5d, u6d = ud

tan_lean = {sin(q2)/cos(q2): tan(q2)}
# Create variables for to act as place holders in the vector from FO to FN
g31 = Function('g31')(t)
g33 = Function('g33')(t)
g31_s, g33_s = symbols('g31 g33')
g31d_s, g33d_s = symbols('g31d g33d')

"""
# Some simplifying symbols / trig expressions
s1, s2, s3, s4, s5, s6, c1, c2, c3, c4, c5, c6, t2 = symbols('s1 \
        s2 s3 s4 s5 s6 c1 c2 c3 c4 c5 c6 t2')

symbol_subs_dict = {sin(q1): s1,
                    cos(q1): c1,
                    tan(q2): t2,
                    cos(q2): c2,
                    sin(q2): s2,
                    cos(q3): c3,
开发者ID:certik,项目名称:pydy,代码行数:31,代码来源:bicycle.py


示例17: var

var("x y")
d_u = Symbol("D_u")
d_v = Symbol("D_v")
sigma = Symbol("SIGMA")
lam = Symbol("LAMBDA")
kappa = Symbol("KAPPA")
k = Symbol("K")

def eq1(u, v, f):
    return -d_u*d_u*(u.diff(x, 2) + u.diff(y, 2)) - f(u) + sigma*v

def eq2(u, v):
    return -d_v*d_v*(v.diff(x, 2) + v.diff(y, 2)) - u + v

u = Function("u")
v = Function("v")
print "Reaction-Diffusion Equations:"
def f(u):
    return lam*u-u**3-kappa
pprint(eq1(u(x, y), v(x, y), f))
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
开发者ID:B-Rich,项目名称:hermes-legacy,代码行数:29,代码来源:generate_equation_data.py


示例18: symbols

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
开发者ID:CFD-GO,项目名称:TCLB_tools,代码行数:31,代码来源:experiments_derivatives.py



注:本文中的sympy.Function类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sympy.GoldenRatio类代码示例发布时间:2022-05-27
下一篇:
Python sympy.Float类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap