当前位置: 首页>>代码示例>>Python>>正文


Python sympy.Function类代码示例

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


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


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