Esempio n. 1
0
 def _get_variance(self):
     if self._variance is not None:
         return self._variance
     else:
         from sympy import integrate, trim, together
         w = Symbol('w', real=True, dummy=True)
         self._variance = integrate(self.pdf(w)*w**2,(w,self.domain[0],self.domain[1])) - self.mean**2
         self._variance = trim(self._variance)
         return self._variance
Esempio n. 2
0
 def _get_variance(self):
     if self._variance is not None:
         return self._variance
     else:
         from sympy import integrate, trim, together
         w = Symbol('w', real=True, dummy=True)
         self._variance = integrate(self.pdf(w)*w**2,(w,self.domain[0],self.domain[1])) - self.mean**2
         self._variance = trim(self._variance)
         return self._variance
Esempio n. 3
0
from __future__ import division
from sympy import Matrix, pi, sqrt, trim, log
from sympy.mpmath import mp
from veccalc import *

# Cartesian.
cs = CartesianCS

q = 1.602176487e-19
Phi = 1 / (4 * pi) * q / sqrt(cs.x**2 + cs.y**2 + cs.z**2)
E = Matrix([1 / (4 * pi) * q * cs.x / (cs.x**2 + cs.y**2 + cs.z**2)**(3/2), \
            1 / (4 * pi) * q * cs.y / (cs.x**2 + cs.y**2 + cs.z**2)**(3/2),
            1 / (4 * pi) * q * cs.z / (cs.x**2 + cs.y**2 + cs.z**2)**(3/2)])

assert trim(E[0]) == trim(-cs.grad(Phi)[0])
assert cs.curl(E) == Matrix([0, 0, 0])
# FIXME this is really 0. How to simplify the expression using sympy?
assert cs.div(E).evalf(subs={cs.x: 1, cs.y: 2, cs.z: 3}) < mp.eps

assert cs.grad(cs.x ** 2 + cs.y ** 2) == Matrix([2 * cs.x, 2 * cs.y, 0])

assert cs.laplacian(cs.x ** 2 - cs.y ** 2) == 0

# Cylindrical.
cs = CylindricalCS

i = 2
B = Matrix([0, i / (2 * pi * cs.r), 0])
assert cs.curl(B) == Matrix([0, 0, 0])
assert cs.div(B) == 0
Esempio n. 4
0
def test_heurisch_symbolic_coeffs():
    assert heurisch(1/(x+y), x)         == log(x+y)
    assert heurisch(1/(x+sqrt(2)), x)   == log(x+sqrt(2))
    assert trim(diff(heurisch(log(x+y+z), y), y)) == log(x+y+z)
Esempio n. 5
0
def test_heurisch_symbolic_coeffs():
    assert heurisch(1/(x+y), x)         == log(x+y)
    assert heurisch(1/(x+sqrt(2)), x)   == log(x+sqrt(2))
    assert trim(diff(heurisch(log(x+y+z), y), y)) == log(x+y+z)
Esempio n. 6
0
def bench_R6():
    "sum(trim((x+sin(i))/x+(x-sin(i))/x) for i in xrange(100))"
    s = sum(trim((x+sin(i))/x+(x-sin(i))/x) for i in xrange(100))
Esempio n. 7
0
def bench_R6():
    "sum(trim((x+sin(i))/x+(x-sin(i))/x) for i in xrange(100))"
    s = sum(trim((x + sin(i)) / x + (x - sin(i)) / x) for i in xrange(100))