How to use the sympy.sqrt function in sympy

To help you get started, we’ve selected a few sympy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / quadpy / quadpy / enr2 / _xiu.py View on Github external
def xiu(n):
    points = []
    for k in range(n + 1):
        pt = []
        # Slight adaptation:
        # The article has points for the weight 1/sqrt(2*pi) exp(−x**2/2)
        # so divide by sqrt(2) to adapt for 1/sqrt(pi) exp(−x ** 2)
        for r in range(1, n // 2 + 1):
            alpha = (2 * r * k * pi) / (n + 1)
            pt += [cos(alpha), sin(alpha)]
        if n % 2 == 1:
            pt += [(-1) ** k / sqrt(2)]
        points.append(pt)

    points = numpy.array(points)
    weights = numpy.full(n + 1, frac(1, n + 1))
    return Enr2Scheme("Xiu", n, weights, points, 2, source)
github sympy / sympy / examples / advanced / qft.py View on Github external
def u(p, r):
    """ p = (p1, p2, p3); r = 0,1 """
    assert r in [1, 2]
    p1, p2, p3 = p
    if r == 1:
        ksi = Matrix([[1], [0]])
    else:
        ksi = Matrix([[0], [1]])
    a = (sigma1*p1 + sigma2*p2 + sigma3*p3) / (E + m) * ksi
    if a == 0:
        a = zeros(2, 1)
    return sqrt(E + m) * Matrix([[ksi[0, 0]], [ksi[1, 0]], [a[0, 0]], [a[1, 0]]])
github uw-biorobotics / IKBT / ikbtleaves / sinANDcos_solver.py View on Github external
if(u.symbol == th_3):
                ntests += 1
                self.assertTrue(u.solved, fs)
                self.assertTrue(u.solutions[0] ==  sp.atan2(l_3, l_3) + sp.atan2(sp.sqrt(2*l_3**2 - (l_2 - l_4 + 5)**2), l_2 - l_4 + 5), fs)
                self.assertTrue(u.solutions[1] == sp.atan2(l_3, l_3) + sp.atan2(-sp.sqrt(2*l_3**2 - (l_2 - l_4 + 5)**2), l_2 - l_4 + 5), fs)
                
                
            if (u.symbol == th_4):
                ntests += 1
                self.assertTrue(not u.solved, fs + ' [th_4]' )
                
            if (u.symbol == th_6):
                ntests  += 1 
                self.assertTrue(u.solutions[0] == sp.atan2(l_1 + l_4, l_3) + sp.atan2(sp.sqrt(-l_2**2 + l_3**2 + (l_1 + l_4)**2), l_2), fs + ' [th_6]')
                self.assertTrue(u.solutions[1] == sp.atan2(l_1 + l_4, l_3) + sp.atan2(-sp.sqrt(-l_2**2 + l_3**2 + (l_1 + l_4)**2), l_2), fs + ' [th_6a]')

        self.assertTrue(ntests == 4, 'sinANDcos_solver:    Assert count fail       FAIL')
github nschloe / quadpy / quadpy / e3r2 / _stroud_secrest.py View on Github external
def _stroud_secrest_11(positive):
    p_m = 1 if positive else -1

    sqrt2 = sqrt(2)
    sqrt5 = sqrt(5)
    sqrt10 = sqrt(10)

    r = sqrt((25 + p_m * 15 * sqrt2 + 5 * sqrt5 + p_m * 3 * sqrt10) / 4)
    s = sqrt((25 + p_m * 15 * sqrt2 - 5 * sqrt5 - p_m * 3 * sqrt10) / 4)
    t = sqrt((3 - p_m * sqrt2) / 2)
    u = sqrt((9 - p_m * 3 * sqrt2 - 3 * sqrt5 + p_m * sqrt10) / 4)
    v = sqrt((9 - p_m * 3 * sqrt2 + 3 * sqrt5 - p_m * sqrt10) / 4)

    A = (80 + p_m * 8 * sqrt2) / 245
    B = (395 - p_m * 279 * sqrt2) / 13720
    C = (45 + p_m * 29 * sqrt2) / 2744

    data = [
        (A, [[0, 0, 0]]),
        (B, pm_roll([r, s, 0])),
        (C, pm_roll([u, v, 0])),
        (C, pm([t, t, t])),
github nschloe / quadpy / quadpy / e3r2 / _stroud_secrest.py View on Github external
def _stroud_secrest_11(positive):
    p_m = 1 if positive else -1

    sqrt2 = sqrt(2)
    sqrt5 = sqrt(5)
    sqrt10 = sqrt(10)

    r = sqrt((25 + p_m * 15 * sqrt2 + 5 * sqrt5 + p_m * 3 * sqrt10) / 4)
    s = sqrt((25 + p_m * 15 * sqrt2 - 5 * sqrt5 - p_m * 3 * sqrt10) / 4)
    t = sqrt((3 - p_m * sqrt2) / 2)
    u = sqrt((9 - p_m * 3 * sqrt2 - 3 * sqrt5 + p_m * sqrt10) / 4)
    v = sqrt((9 - p_m * 3 * sqrt2 + 3 * sqrt5 - p_m * sqrt10) / 4)

    A = (80 + p_m * 8 * sqrt2) / 245
    B = (395 - p_m * 279 * sqrt2) / 13720
    C = (45 + p_m * 29 * sqrt2) / 2744

    data = [
        (A, [[0, 0, 0]]),
        (B, pm_roll([r, s, 0])),
        (C, pm_roll([u, v, 0])),
        (C, pm([t, t, t])),
    ]
    points, weights = untangle(data)
    return E3r2Scheme("Stroud-Secrest XI", weights, points, 7, source)
github nesl / UnrealAirSimDRL / Util / Filters / KalmanFilter.py View on Github external
def measure_move2(x, dt, isSym=False):
        landmark_pos = (5, 5)
        x = np.array(x).reshape(-1)
        if not isSym:
            px = landmark_pos[0]
            py = landmark_pos[1]
            dist = np.sqrt((px - x[0])**2 + (py - x[1])**2)
            hx = np.matrix([[dist],
                            [np.arctan2(py - x[1], px - x[0]) - x[2]]])
            return hx
        else:
            px = landmark_pos[0]
            py = landmark_pos[1]
            dist = sym.sqrt((px - x[0])**2 + (py - x[1])**2)
            hx = sym.Matrix([[dist],
                             [sym.atan2(py - x[1], px - x[0]) - x[2]]])
            return hx
github uw-biorobotics / IKBT / ikbtbasics / kin_cl.py View on Github external
def a_test_kequation(self):   # another kequation test in ik_classes
        e1 = kequation(th_2, sp.sin(th_1)*l_1 + sp.sqrt(l_4))
        e2 = kequation(th_2, sp.sin(th_1)*l_1 / sp.sqrt(l_4))
        print '>>-----------------------------<<'
        print e1
        print e1.LaTexOutput()
        print e1.LaTexOutput(True)
        print '>>-----------------------------<<'
        fs = 'kequation LaTex output  FAIL'
        self.assertTrue(e1.LaTexOutput() == r'\theta_{2} = l_{1} \sin{\left (\theta_{1} \right )} + \sqrt{l_{4}}', fs)
        self.assertTrue(e1.LaTexOutput(True) == r'\theta_{2} &= l_{1} \sin{\left (\theta_{1} \right )} + \sqrt{l_{4}}', fs + ' (align)')

#\theta_{2} = l_{1} \sin{\left (\theta_{1} \right )} + \sqrt{l_{4}}
#\theta_{2} &= l_{1} \sin{\left (\theta_{1} \right )} + \sqrt{l_{4}}

        print '>>-----------------------------<<'
        print e2
        print e2.LaTexOutput()
        print e2.LaTexOutput(True)
github pf4d / cslvr / cslvr / verification.py View on Github external
self.dbdy     = self.b.diff(y, 1)

		# x-derivative of thickness :
		self.dhdx     = self.h.diff(x, 1)

		# y-derivative of thickness :
		self.dhdy     = self.h.diff(y, 1)

		# rate of change of thickness :
		self.dhdt     = self.dsdt - self.dbdt

		# outward-pointing-normal-vector magnitude at upper surface :
		self.n_mag_s  = sp.sqrt( 1 + self.dsdx**2 + self.dsdy**2 )

		# outward-pointing-normal-vector magnitude at lower surface :
		self.n_mag_b  = sp.sqrt( 1 + self.dbdx**2 + self.dbdy**2 )

		# thickness forcing term :
		self.h_ring   = self.n_mag_s * self.s_ring + self.n_mag_b * self.b_ring

		# x-derivative of the x-component of velocity at the upper surface :
		self.du_xs_dx = self.u_xs.diff(x, 1)

		# y-derivative of the x-component of velocity at the upper surface :
		self.du_xs_dy = self.u_xs.diff(y, 1)

		# x-derivative of the x-component of velocity at the lower surface :
		self.du_xb_dx = self.u_xb.diff(x, 1)

		# y-derivative of the x-component of velocity at the lower surface :
		self.du_xb_dy = self.u_xb.diff(y, 1)
github uw-biorobotics / IKBT / ikbtleaves / sincos_solver.py View on Github external
Ts = sp.zeros(5)

      Td[0,1] = l_1
      Ts[0,1] = sp.cos(th_1)*l_2 + (l_3+l_4)*sp.cos(th_1) + l_5

      Td[1,1] = l_1
      Ts[1,1] = sp.sin(th_3)

      Td[1,2] = l_2
      Ts[1,2] = sp.cos(th_2)

      Td[2,1] = l_2+5
      Ts[2,1] = l_1*sp.cos(th_4)
      
      Td[2,2] = l_2
      Ts[2,2] = sp.sqrt(th_5)

      Td[2,3] = l_2
      Ts[2,3] = sp.cos(th_5)*sp.sin(th_2)
      
      Td[3,1] = l_2 + l_1
      Ts[3,1] = th_2+sp.cos(th_4)*l_3

      Td[3,2] = 17
      Ts[3,2] = l_1*sp.sin(th_3) + 2*l_2*sp.cos(th_3)

      testm = matrix_equation(Td,Ts)        
      R = Robot()
      R.mequation_list = [testm]
      
      uth1 = unknown(th_1)
      uth2 = unknown(th_2)
github nschloe / quadpy / quadpy / enr2 / _stroud_secrest.py View on Github external
def stroud_secrest_4(n):
    nu = sqrt(frac(n + 2, 2))
    xi = sqrt(frac(n + 2, 4))
    A = frac(2, n + 2)
    B = frac(4 - n, 2 * (n + 2) ** 2)
    C = frac(1, (n + 2) ** 2)

    data = [(A, numpy.full((1, n), 0)), (B, fsd(n, (nu, 1))), (C, fsd(n, (xi, 2)))]
    points, weights = untangle(data)
    return Enr2Scheme("Stroud-Secrest IV", n, weights, points, 5, source)