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


Python sympy.integrate函数代码示例

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


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

示例1: test_issue841

def test_issue841():
    from sympy import expand_mul
    from sympy.abc import k

    assert expand_mul(integrate(exp(-x ** 2) * exp(I * k * x), (x, -oo, oo))) == sqrt(pi) * exp(-k ** 2 / 4)
    a, d = symbols("a d", positive=True)
    assert expand_mul(integrate(exp(-a * x ** 2 + 2 * d * x), (x, -oo, oo))) == sqrt(pi) * exp(d ** 2 / a) / sqrt(a)
开发者ID:arunenigma,项目名称:sympy,代码行数:7,代码来源:test_integrals.py

示例2: test_integrate_omit_var

def test_integrate_omit_var():
    y = Symbol('y')

    assert integrate(x) == x**2/2

    raises(ValueError, lambda: integrate(2))
    raises(ValueError, lambda: integrate(x*y))
开发者ID:baoqchau,项目名称:sympy,代码行数:7,代码来源:test_integrals.py

示例3: test_integrate_linearterm_pow

def test_integrate_linearterm_pow():
    # check integrate((a*x+b)^c, x)  --  issue 3499
    y = Symbol('y', positive=True)
    # TODO: Remove conds='none' below, let the assumption take care of it.
    assert integrate(x**y, x, conds='none') == x**(y + 1)/(y + 1)
    assert integrate((exp(y)*x + 1/y)**(1 + sin(y)), x, conds='none') == \
        exp(-y)*(exp(y)*x + 1/y)**(2 + sin(y)) / (2 + sin(y))
开发者ID:baoqchau,项目名称:sympy,代码行数:7,代码来源:test_integrals.py

示例4: setThreshold

	def setThreshold(self):
		import sympy
		# f(x) is probability density of processing times 
		# Using Bounded Pareto,
			# f(x) = {0 if x < 0, main.customEquation if x >= 0}
		# Probability jobs will be in class 1, ie. their processing time will be between Lower and Threshold
		# Prob(Lower <= procTime <= Threshold) = integral{from L to T}f(x)dx >> 0.8 (should be very close to 1)
		# Most jobs will be small, only a few will be big

		# ???
		# lambda * integral{from L to U} x*f(x) dx < numServers

		#HOW TO FIND THRESHOLD
		# integral{from L to T} x*f(x)dx / integral{from L to U} x*f(x)dx = 0.8 (becasue 80% of jobs will be small)
		# solve for T
		x, L, U, T, alpha = sympy.symbols('x L U T alpha', real=True)
		
		numerator = sympy.integrate((x*BoundedParetoDist.Function), (x, L, T))
		denominator = sympy.integrate((x*BoundedParetoDist.Function), (x, L, U))
		expected = numerator/denominator

		#expected = expected.subs(dict(alpha=JobClass.BPArray[0], L=JobClass.BPArray[1], U=JobClass.BPArray[2]))
		expected = expected.subs([(alpha, JobClass.BPArray[0]), (L, JobClass.BPArray[1]), (U, JobClass.BPArray[2])])
		#print "expected subed"
		#print expected
		
		#Equate expected = 0.8, solve for T
		#thresholdRange = sympy.solve(sympy.Eq(expected, 0.8), T)
		#MachineClass.Threshold = thresholdRange[1] #set only positive number

		##FORCE THRESHOLD AS LOGICAL VALUE
		MachineClass.Threshold = 800000
		GUI.writeToConsole(self.master, "Class threshold = %s"%MachineClass.Threshold)
开发者ID:rsmailach,项目名称:MultiServerSRPT,代码行数:33,代码来源:SRPTE_Multi_KnownDist.py

示例5: 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))
开发者ID:baoqchau,项目名称:sympy,代码行数:32,代码来源:test_integrals.py

示例6: compute_psi_stats

    def compute_psi_stats(self):
        # define some normal distributions
        mus = [sp.var("mu_%i" % i, real=True) for i in range(self.input_dim)]
        Ss = [sp.var("S_%i" % i, positive=True) for i in range(self.input_dim)]
        normals = [
            (2 * sp.pi * Si) ** (-0.5) * sp.exp(-0.5 * (xi - mui) ** 2 / Si) for xi, mui, Si in zip(self._sp_x, mus, Ss)
        ]

        # do some integration!
        # self._sp_psi0 = ??
        self._sp_psi1 = self._sp_k
        for i in range(self.input_dim):
            print "perfoming integrals %i of %i" % (i + 1, 2 * self.input_dim)
            sys.stdout.flush()
            self._sp_psi1 *= normals[i]
            self._sp_psi1 = sp.integrate(self._sp_psi1, (self._sp_x[i], -sp.oo, sp.oo))
            clear_cache()
        self._sp_psi1 = self._sp_psi1.simplify()

        # and here's psi2 (eek!)
        zprime = [sp.Symbol("zp%i" % i) for i in range(self.input_dim)]
        self._sp_psi2 = self._sp_k.copy() * self._sp_k.copy().subs(zip(self._sp_z, zprime))
        for i in range(self.input_dim):
            print "perfoming integrals %i of %i" % (self.input_dim + i + 1, 2 * self.input_dim)
            sys.stdout.flush()
            self._sp_psi2 *= normals[i]
            self._sp_psi2 = sp.integrate(self._sp_psi2, (self._sp_x[i], -sp.oo, sp.oo))
            clear_cache()
        self._sp_psi2 = self._sp_psi2.simplify()
开发者ID:rajivsam,项目名称:GPy,代码行数:29,代码来源:sympykern.py

示例7: E

 def E(expr):
     res1 = integrate(expr*exponential(x, rate)*normal(y, mu1, sigma1),
                      (x, 0, oo), (y, -oo, oo), meijerg=True)
     res2 = integrate(expr*exponential(x, rate)*normal(y, mu1, sigma1),
                     (y, -oo, oo), (x, 0, oo), meijerg=True)
     assert expand_mul(res1) == expand_mul(res2)
     return res1
开发者ID:chaffra,项目名称:sympy,代码行数:7,代码来源:test_meijerint.py

示例8: test_integrate_linearterm_pow

def test_integrate_linearterm_pow():
    # check integrate((a*x+b)^c, x)  --  #400
    y = Symbol("y")
    assert integrate(x ** y, x) == x ** (y + 1) / (y + 1)
    assert integrate((exp(y) * x + 1 / y) ** (1 + sin(y)), x) == exp(-y) * (exp(y) * x + 1 / y) ** (2 + sin(y)) / (
        2 + sin(y)
    )
开发者ID:vks,项目名称:sympy,代码行数:7,代码来源:test_integrals.py

示例9: test_issue_1791

def test_issue_1791():
    z = Symbol("z", positive=True)
    assert integrate(exp(-log(x) ** 2), x) == pi ** (S(1) / 2) * erf(-S(1) / 2 + log(x)) * exp(S(1) / 4) / 2
    assert integrate(exp(log(x) ** 2), x) == -I * pi ** (S(1) / 2) * erf(I * log(x) + I / 2) * exp(-S(1) / 4) / 2
    assert integrate(exp(-z * log(x) ** 2), x) == pi ** (S(1) / 2) * erf(
        z ** (S(1) / 2) * log(x) - 1 / (2 * z ** (S(1) / 2))
    ) * exp(S(1) / (4 * z)) / (2 * z ** (S(1) / 2))
开发者ID:vks,项目名称:sympy,代码行数:7,代码来源:test_integrals.py

示例10: T_exact_symbolic

def T_exact_symbolic(verbose=False):
    """Compute the exact solution formula via sympy."""
    # sol1: solution for t < t_star,
    # sol2: solution for t > t_star
    import sympy as sym
    T0 = sym.symbols('T0')
    k = sym.symbols('k', positive=True)
    # Piecewise linear T_sunction
    t, t_star, C0, C1 = sym.symbols('t t_star C0 C1')
    T_s = C0
    I = sym.integrate(sym.exp(k*t)*T_s, (t, 0, t))
    sol1 = T0*sym.exp(-k*t) + k*sym.exp(-k*t)*I
    sol1 = sym.simplify(sym.expand(sol1))
    if verbose:
        # Some debugging print
        print 'solution t < t_star:', sol1
        #print sym.latex(sol1)
    T_s = C1
    I = sym.integrate(sym.exp(k*t)*C0, (t, 0, t_star)) + \
        sym.integrate(sym.exp(k*t)*C1, (t, t_star, t))
    sol2 = T0*sym.exp(-k*t) + k*sym.exp(-k*t)*I
    sol2 = sym.simplify(sym.expand(sol2))
    if verbose:
        print 'solution t > t_star:', sol2
        #print sym.latex(sol2)

    # Convert to numerical functions
    exact0 = sym.lambdify([t, C0, k, T0],
                          sol1, modules='numpy')
    exact1 = sym.lambdify([t, C0, C1, t_star, k, T0],
                          sol2, modules='numpy')
    return exact0, exact1
开发者ID:hplgit,项目名称:decay-book,代码行数:32,代码来源:cooling.py

示例11: __init__

    def __init__(
            self,
            tau,  # A float
            start=None,
            ):
        print('''
tau={0}'''.format(tau))
        if start==None:
            start = tau -.05 + 2*tau
        x,lam = sympy.symbols('x lam'.split())
        self.tau = tau
        k = 0
        term = 1.0 + x*0   # \frac{1}{k!} * (-\frac{x}{lam})^k
        pk = 0             # sum_{n=0}^k term_k
        cum_prod = 1       # prod_{n=0}^k pk(tau)
        integral = 0       # integral_0^? rho(s) ds
        while tau*k < 1.0:
            pk += term              # Polynomial of x/lam
            pk_tau = pk.subs(x,tau) # Polynomial of tau/lam
            print('''  k={0}
  term={1}
  pk={2}
  '''.format(k, term, pk))
            if tau*(k+1) >= 1.0:
                d = 1.0 - tau*k
                integral += sympy.integrate(pk, (x, 0, d))/cum_prod
                break
            integral += sympy.integrate(pk, (x, 0, tau))/cum_prod
            # integral is a rational function of tau and lam
            cum_prod *= pk_tau      # Polynomial of tau/lam
            k += 1
            term *= -x/(k*lam)      # Monomial of x/lam
        print('''  cum_prod={2}  Solving
  {0}={1}'''.format(lam,integral.simplify(), cum_prod))
        self.eigenvalue = sympy.solve(lam-integral, lam)
开发者ID:fraserphysics,项目名称:metfie,代码行数:35,代码来源:sym.py

示例12: integrar

    def integrar(self):

        f = self.ui.lineEdit_int_funcion.text()

        f_var = [Symbol(self.ui.lineEdit_int_var_1.text()),
            Symbol(self.ui.lineEdit_int_var_2.text()),
            Symbol(self.ui.lineEdit_int_var_3.text())]

        f_min = [(self.ui.lineEdit_int_min_1.text()),
            (self.ui.lineEdit_int_min_2.text()),
            (self.ui.lineEdit_int_min_3.text())]

        f_max = [(self.ui.lineEdit_int_max_1.text()),
            (self.ui.lineEdit_int_max_2.text()),
            (self.ui.lineEdit_int_max_3.text())]

        for i in range(0, int(self.ui.spinBox_int.text())):
            if self.ui.radioButton_int_def.isChecked() is True:
                f = integrate(f, (f_var[i], f_min[i], f_max[i]))
                self.ui.label_int_solucion.setText(str(f))
                print (f)

            else:
                f = integrate(f, f_var[i])
                self.ui.label_int_solucion.setText(str(f))
                print (f)
开发者ID:zerberros,项目名称:tercera_mano,代码行数:26,代码来源:tercera_mano.py

示例13: benefit_from_demand

def benefit_from_demand(x, p, demand):
    """Converts the demand curve to the benefit.  It assumes that the
    demand is a x=d(p) function, where the x= is implicit.

    >>> sp.var('x p')
    (x, p)
    >>> sp.simplify(benefit_from_demand(x, p, 10/p -1) -
    ...             10*sp.log(x+1))
    0
    >>> sp.simplify(benefit_from_demand(x, p, sp.Eq(x, 10/p -1)) -
    ...             10*sp.log(x+1))
    0
    >>> sp.simplify(benefit_from_demand(x, p, 100-p) -
    ...             (-x**2/2 + 100*x))
    0
    >>> benefit_from_demand(x, p, sp.Piecewise((0, p < 0),
    ...                                        (-p + 100, p <= 100),
    ...                                        (0, True)))
    -x**2/2 + 100*x
    """
    if isinstance(demand, sp.relational.Relational):
        return sp.integrate(sp.solve(demand, p)[0], (x, 0, x))
    substracting = sp.solve(demand-x, p)
    if substracting:
        toint = substracting[0]
    else:
        substracting = sp.solve(demand, p)
        if substracting:
            toint = substracting[0] - x
        else:
            return None

    return sp.integrate(toint, (x, 0, x))
开发者ID:juanre,项目名称:econopy,代码行数:33,代码来源:tools.py

示例14: integrate_f_over_polygon_code

def integrate_f_over_polygon_code(f):
    """Generate code that will integrate a function over a polygon

    Parameters
    ----------
    f : sympy expression
        Expression to be integrated over the polygon.

    Returns
    -------
    out : str
        Multiline string of function code

    """

    x, y, z=sympy.symbols('x,y,z')
    x0, x1, y0, y1, z0, z1=sympy.symbols('x0,x1,y0,y1,z0,z1')
    t = sympy.symbols('t')
    s2 = [(x, x0+t*(x1-x0)), (y, y0+t*(y1-y0)), (z, z0+t*(z1-z0))]

    ff = sympy.integrate(f,x)
    ff = ff.subs(s2)
    ff = sympy.integrate(ff, (t,0,1))
    ff *= (y1 - y0) #if integrating in y direction 1st then *-(x1-x0)

    ff = replace_x0_and_x1_with_vect(ff)

    template ="""def ifxy(pts):
    "Integrate f = {} over polygon"

    x, y, z = xyz_from_pts(pts, True)

    return np.sum({})"""

    return template.format(str(f), ff)
开发者ID:rtrwalker,项目名称:geotecha,代码行数:35,代码来源:geometry.py

示例15: case0

def case0(f, N=3):
    B = 1 - x ** 3
    dBdx = sm.diff(B, x)

    # Compute basis functions and their derivatives
    phi = {0: [x ** (i + 1) * (1 - x) for i in range(N + 1)]}
    phi[1] = [sm.diff(phi_i, x) for phi_i in phi[0]]

    def integrand_lhs(phi, i, j):
        return phi[1][i] * phi[1][j]

    def integrand_rhs(phi, i):
        return f * phi[0][i] - dBdx * phi[1][i]

    Omega = [0, 1]

    u_bar = solve(integrand_lhs, integrand_rhs, phi, Omega, verbose=True, numint=False)
    u = B + u_bar
    print "solution u:", sm.simplify(sm.expand(u))

    # Calculate analytical solution

    # Solve -u''=f by integrating f twice
    f1 = sm.integrate(f, x)
    f2 = sm.integrate(f1, x)
    # Add integration constants
    C1, C2 = sm.symbols("C1 C2")
    u_e = -f2 + C1 * x + C2
    # Find C1 and C2 from the boundary conditions u(0)=0, u(1)=1
    s = sm.solve([u_e.subs(x, 0) - 1, u_e.subs(x, 1) - 0], [C1, C2])
    # Form the exact solution
    u_e = -f2 + s[C1] * x + s[C2]
    print "analytical solution:", u_e
    # print 'error:', u - u_e  # many terms - which cancel
    print "error:", sm.expand(u - u_e)
开发者ID:jorisVerschaeve,项目名称:INF5620,代码行数:35,代码来源:ex_varform1D.py


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