コード例 #1
0
def test_subs7():
    e = Integral(x, (x, 1, y), (y, 1, 2))
    assert e.subs({x: 1, y: 2}) == e
    e = Integral(sin(x) + sin(y), (x, sin(x), sin(y)), (y, 1, 2))
    assert e.subs(sin(y), 1) == e
    assert e.subs(sin(x),
                  1) == Integral(sin(x) + sin(y), (x, 1, sin(y)), (y, 1, 2))
コード例 #2
0
def test_subs4():
    e = Integral(exp(x), (x, 0, y), (t, y, 1))
    assert e.subs(y, 3) == Integral(exp(x), (x, 0, 3), (t, 3, 1))
    f = Lambda(x, exp(-x**2))
    conv = Integral(f(y) * f(y), (y, -oo, oo), (t, x, 1))
    assert conv.subs({x: 0}) == Integral(exp(-2 * y**2), (y, -oo, oo),
                                         (t, 0, 1))
コード例 #3
0
ファイル: test_subs.py プロジェクト: DarylMcCullough/sympy
def test_issue_14796():
    f,g = symbols("f g", cls=Function)
    x,y = symbols("x y")
    
    # substitute one undefined function for another
    int_expr = Integral(f(x), (x,0,1))
    int_expr2 = Integral(g(x), (x,0,1))
    int_expr3 = int_expr.subs(f, g)
    assert int_expr2 == int_expr3
    
    # substitute a built-in function for an undefined function
    int_expr4 = int_expr.subs(f, cos)
    int_expr5 = Integral(cos(x), (x,0,1))
    assert int_expr4 == int_expr5
    
    # substitute an undefined function for a built-in function
    assert int_expr == int_expr5.subs(cos, f)
    
    # substitute a symbol for an undefined function (does nothing)
    int_expr6 = int_expr.subs(f, y)
    int_expr7 = Integral(y(x), (x,0,1))
    assert int_expr6 != int_expr7
    assert int_expr6 == int_expr
    
    # substitute a lambda for an undefined function
    l = Lambda(y, g(y))
    int_expr8 = Integral(g(x), (x,0,1))
    int_expr9 = int_expr.subs(f, l)
    assert int_expr9 == int_expr8
コード例 #4
0
def test_subs1():
    e = Integral(exp(x - y), x)
    assert e.subs(y, 3) == Integral(exp(x - 3), x)
    e = Integral(exp(x - y), (x, 0, 1))
    assert e.subs(y, 3) == Integral(exp(x - 3), (x, 0, 1))
    f = Lambda(x, exp(-x**2))
    conv = Integral(f(x - y) * f(y), (y, -oo, oo))
    assert conv.subs({x: 0}) == Integral(exp(-2 * y**2), (y, -oo, oo))
コード例 #5
0
ファイル: test_integrals.py プロジェクト: baoqchau/sympy
def test_subs7():
    e = Integral(x, (x, 1, y), (y, 1, 2))
    assert e.subs({x: 1, y: 2}) == e
    e = Integral(sin(x) + sin(y), (x, sin(x), sin(y)),
                                  (y, 1, 2))
    assert e.subs(sin(y), 1) == e
    assert e.subs(sin(x), 1) == Integral(sin(x) + sin(y), (x, 1, sin(y)),
                                         (y, 1, 2))
コード例 #6
0
ファイル: test_integrals.py プロジェクト: baoqchau/sympy
def test_subs2():
    e = Integral(exp(x - y), x, t)
    assert e.subs(y, 3) == Integral(exp(x - 3), x, t)
    e = Integral(exp(x - y), (x, 0, 1), (t, 0, 1))
    assert e.subs(y, 3) == Integral(exp(x - 3), (x, 0, 1), (t, 0, 1))
    f = Lambda(x, exp(-x**2))
    conv = Integral(f(x - y)*f(y), (y, -oo, oo), (t, 0, 1))
    assert conv.subs({x: 0}) == Integral(exp(-2*y**2), (y, -oo, oo), (t, 0, 1))
コード例 #7
0
def test_subs6():
    a, b = symbols('a b')
    e = Integral(x * y, (x, f(x), f(y)))
    assert e.subs(x, 1) == Integral(x * y, (x, f(1), f(y)))
    assert e.subs(y, 1) == Integral(x, (x, f(x), f(1)))
    e = Integral(x * y, (x, f(x), f(y)), (y, f(x), f(y)))
    assert e.subs(x, 1) == Integral(x * y, (x, f(1), f(y)), (y, f(1), f(y)))
    assert e.subs(y, 1) == Integral(x * y, (x, f(x), f(y)), (y, f(x), f(1)))
    e = Integral(x * y, (x, f(x), f(a)), (y, f(x), f(a)))
    assert e.subs(a, 1) == Integral(x * y, (x, f(x), f(1)), (y, f(x), f(1)))
コード例 #8
0
ファイル: test_integrals.py プロジェクト: baoqchau/sympy
def test_subs6():
    a, b = symbols('a b')
    e = Integral(x*y, (x, f(x), f(y)))
    assert e.subs(x, 1) == Integral(x*y, (x, f(1), f(y)))
    assert e.subs(y, 1) == Integral(x, (x, f(x), f(1)))
    e = Integral(x*y, (x, f(x), f(y)), (y, f(x), f(y)))
    assert e.subs(x, 1) == Integral(x*y, (x, f(1), f(y)), (y, f(1), f(y)))
    assert e.subs(y, 1) == Integral(x*y, (x, f(x), f(y)), (y, f(x), f(1)))
    e = Integral(x*y, (x, f(x), f(a)), (y, f(x), f(a)))
    assert e.subs(a, 1) == Integral(x*y, (x, f(x), f(1)), (y, f(x), f(1)))
コード例 #9
0
ファイル: test_integrals.py プロジェクト: wxgeo/sympy
def test_subs5():
    e = Integral(exp(-x**2), x)
    assert e.subs(x, 5) == Integral(exp(-x**2), (x, 5))
    e = Integral(exp(-x**2), (x, -oo, oo))
    assert e.subs(x, 5) == e
    e = Integral(exp(-x**2+y), x)
    assert e.subs(x, 5) == Integral(exp(y - x**2), (x, 5))
    assert e.subs(y, 5) == Integral(exp(-x**2+5), x)
    e = Integral(exp(-x**2+y), (y, -oo, oo), (x, -oo, oo))
    assert e.subs(x, 5) == e
    assert e.subs(y, 5) == e
コード例 #10
0
ファイル: test_integrals.py プロジェクト: hunteke/sympy
def test_subs5():
    e = Integral(exp(-x**2), x)
    assert e.subs(x, 5) == Integral(exp(-x**2), (x, 5))
    e = Integral(exp(-x**2), (x, -oo, oo))
    assert e.subs(x, 5) == e
    e = Integral(exp(-x**2+y), x)
    assert e.subs(x, 5) == Integral(exp(y - x**2), (x, 5))
    assert e.subs(y, 5) == Integral(exp(-x**2+5), x)
    e = Integral(exp(-x**2+y), (y, -oo, oo), (x, -oo, oo))
    assert e.subs(x, 5) == e
    assert e.subs(y, 5) == e
コード例 #11
0
ファイル: test_functions.py プロジェクト: rohith2506/sympy
def test_get_motion_methods():
    # Initialization
    t = dynamicsymbols._t
    s1, s2, s3 = symbols("s1 s2 s3")
    S1, S2, S3 = symbols("S1 S2 S3")
    S4, S5, S6 = symbols("S4 S5 S6")
    t1, t2 = symbols("t1 t2")
    a, b, c = dynamicsymbols("a b c")
    ad, bd, cd = dynamicsymbols("a b c", 1)
    a2d, b2d, c2d = dynamicsymbols("a b c", 2)
    v0 = S1 * N.x + S2 * N.y + S3 * N.z
    v01 = S4 * N.x + S5 * N.y + S6 * N.z
    v1 = s1 * N.x + s2 * N.y + s3 * N.z
    v2 = a * N.x + b * N.y + c * N.z
    v2d = ad * N.x + bd * N.y + cd * N.z
    v2dd = a2d * N.x + b2d * N.y + c2d * N.z
    # Test position parameter
    assert get_motion_params(frame=N) == (0, 0, 0)
    assert get_motion_params(N, position=v1) == (0, 0, v1)
    assert get_motion_params(N, position=v2) == (v2dd, v2d, v2)
    # Test velocity parameter
    assert get_motion_params(N, velocity=v1) == (0, v1, v1 * t)
    assert get_motion_params(N, velocity=v1, position=v0, timevalue1=t1) == (0, v1, v0 + v1 * (t - t1))
    assert get_motion_params(N, velocity=v1, position=v2, timevalue1=t1) == (0, v1, v1 * t - v1 * t1 + v2.subs(t, t1))
    integral_vector = Integral(a, t) * N.x + Integral(b, t) * N.y + Integral(c, t) * N.z
    assert get_motion_params(N, velocity=v2, position=v0, timevalue1=t1) == (
        v2d,
        v2,
        v0 + integral_vector - integral_vector.subs(t, t1),
    )
    # Test acceleration parameter
    assert get_motion_params(N, acceleration=v1) == (v1, v1 * t, v1 * t ** 2 / 2)
    assert get_motion_params(N, acceleration=v1, velocity=v0, position=v2, timevalue1=t1, timevalue2=t2) == (
        v1,
        (v0 + v1 * t - v1 * t2),
        -v0 * t1 + v1 * t ** 2 / 2 + v1 * t2 * t1 - v1 * t1 ** 2 / 2 + t * (v0 - v1 * t2) + v2.subs(t, t1),
    )
    assert get_motion_params(N, acceleration=v1, velocity=v0, position=v01, timevalue1=t1, timevalue2=t2) == (
        v1,
        v0 + v1 * t - v1 * t2,
        -v0 * t1 + v01 + v1 * t ** 2 / 2 + v1 * t2 * t1 - v1 * t1 ** 2 / 2 + t * (v0 - v1 * t2),
    )
    i = Integral(a, t)
    i_sub = i.subs(t, t2)
    assert get_motion_params(
        N, acceleration=a * N.x, velocity=S1 * N.x, position=S2 * N.x, timevalue1=t1, timevalue2=t2
    ) == (
        a * N.x,
        (S1 + i - i_sub) * N.x,
        (S2 + Integral(S1 - t * (a.subs(t, t2)) + i, t) - Integral(S1 - t1 * (a.subs(t, t2)) + i.subs(t, t1), t)) * N.x,
    )
コード例 #12
0
ファイル: test_integrals.py プロジェクト: FedericoV/sympy
def test_subs5():
    e = Integral(exp(-x**2), (x, -oo, oo))
    assert e.subs(x, 5) == e
    e = Integral(exp(-x**2 + y), x)
    assert e.subs(y, 5) == Integral(exp(-x**2 + 5), x)
    e = Integral(exp(-x**2 + y), (x, x))
    assert e.subs(x, 5) == Integral(exp(y - x**2), (x, 5))
    assert e.subs(y, 5) == Integral(exp(-x**2 + 5), x)
    e = Integral(exp(-x**2 + y), (y, -oo, oo), (x, -oo, oo))
    assert e.subs(x, 5) == e
    assert e.subs(y, 5) == e
    # Test evaluation of antiderivatives
    e = Integral(exp(-x**2), (x, x))
    assert e.subs(x, 5) == Integral(exp(-x**2), (x, 5))
    e = Integral(exp(x), x)
    assert (e.subs(x,1)-e.subs(x,0) - Integral(exp(x),(x,0,1))).doit().is_zero
コード例 #13
0
def test_subs5():
    e = Integral(exp(-x**2), (x, -oo, oo))
    assert e.subs(x, 5) == e
    e = Integral(exp(-x**2 + y), x)
    assert e.subs(y, 5) == Integral(exp(-x**2 + 5), x)
    e = Integral(exp(-x**2 + y), (x, x))
    assert e.subs(x, 5) == Integral(exp(y - x**2), (x, 5))
    assert e.subs(y, 5) == Integral(exp(-x**2 + 5), x)
    e = Integral(exp(-x**2 + y), (y, -oo, oo), (x, -oo, oo))
    assert e.subs(x, 5) == e
    assert e.subs(y, 5) == e
    # Test evaluation of antiderivatives
    e = Integral(exp(-x**2), (x, x))
    assert e.subs(x, 5) == Integral(exp(-x**2), (x, 5))
    e = Integral(exp(x), x)
    assert (e.subs(x,1)-e.subs(x,0) - Integral(exp(x),(x,0,1))).doit().is_zero
コード例 #14
0
ファイル: test_integrals.py プロジェクト: baoqchau/sympy
def test_subs4():
    e = Integral(exp(x), (x, 0, y), (t, y, 1))
    assert e.subs(y, 3) == Integral(exp(x), (x, 0, 3), (t, 3, 1))
    f = Lambda(x, exp(-x**2))
    conv = Integral(f(y)*f(y), (y, -oo, oo), (t, x, 1))
    assert conv.subs({x: 0}) == Integral(exp(-2*y**2), (y, -oo, oo), (t, 0, 1))
コード例 #15
0
from sympy import solve, symbols, lambdify, diff, Integral, exp, pprint, pretty, simplify
import matplotlib.pyplot as plt
import numpy as np

t = symbols('t', positive=True)
# The approximate rate of change in the number​ (in billions) of monthly text messages is given by the equation
F = 8.1 * t - 16.3
# where t represents the number of years since 2000

#  In 2005 ​(t=5​) there were approximately 9.6 billion monthly text messages
year, value = 5, 9.6

# Find the function that gives the total number​ (in billions) of monthly text messages in year t
F = Integral(F, t).doit()

C = F.subs({t: year}) - value

fun = F - C

# According to this​ function, how many monthly text messages were there in​ 2009 ( 2009 - 2000 )
y = 2009 - 2000
round(fun.subs({t: y}), 2)
コード例 #16
0
ファイル: 01.py プロジェクト: bmoretz/Python-Playground
                   pprint, Integral)
import matplotlib.pyplot as plt
import numpy as np

# The number of​ bachelor's degrees conferred has been increasing steadily in recent decades.
# The rate of change of the number of​ bachelor's degrees​ (in thousands) can be approximated by the following function where t is the number of years since 1970.

t = symbols('t')
dB = 0.0651 * t**2 - 1.939 * t + 16.31

# Divide by 1000
y_min = 833300 / 1000

B = Integral(dB, t).doit() + y_min

B.subs({t: 0}) == y_min  # Verify

# Find Upper B(t)​, given that about 819,900 degrees were conferred in 1970 ​(t=​0).
pprint(B)

# Use the formula from part a. to project the number of​ bachelor's degrees that will be conferred in 2010, t = 40
year_tofind = 40

deg_2010 = B.subs({t: year_tofind})
degrees = round(deg_2010 * 1000)
degrees

# What does the degree distribution look like?

g_xlim = [0, 50]