• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(10622)  |  Call(9146)  |  Derive(0)  |  Import(1476)
sqrt(x)

Return the square root of x.

src/s/h/shedskin-HEAD/examples/sieve.py   shedskin(Download)
from math import sqrt, ceil
from sys import argv
 
def sieveOfAtkin(end):
    """sieveOfAtkin(end): return a list of all the prime numbers <end
    using the Sieve of Atkin."""
    # Code by Steve Krenzel, <Sgk284@gmail.com>, improved
    # Code: http://krenzel.info/?p=83
    # Info: http://en.wikipedia.org/wiki/Sieve_of_Atkin
    assert end > 0, "end must be >0"
    lng = ((end // 2) - 1 + end % 2)
    sieve = [False] * (lng + 1)
 
    x_max, x2, xd = int(sqrt((end-1)/4.0)), 0, 4
    x_max, x2, xd = int(sqrt((end-1)/4.0)), 0, 4
    for xd in xrange(4, 8*x_max + 2, 8):
        x2 += xd
        y_max = int(sqrt(end-x2))
        n, n_diff = x2 + y_max*y_max, (y_max << 1) - 1
        if not (n & 1):
            n -= n_diff
                sieve[m] = not sieve[m]
            n -= d
 
    x_max, x2, xd = int(sqrt((end-1) / 3.0)), 0, 3
    for xd in xrange(3, 6 * x_max + 2, 6):
        x2 += xd
        y_max = int(sqrt(end-x2))
                sieve[m] = not sieve[m]
            n -= d
 
    x_max, y_min, x2, xd = int((2 + sqrt(4-8*(1-end)))/4), -1, 0, 3
    for x in xrange(1, x_max + 1):
        x2 += xd
        xd += 6
        if x2 >= end: y_min = (((int(ceil(sqrt(x2 - end))) - 1) << 1) - 2) << 1
    if end <= 3:
        return primes[:max(0,end-2)]
 
    for n in xrange(5 >> 1, (int(sqrt(end))+1) >> 1):
        if sieve[n]:
            primes.append((n << 1) + 1)
            aux = (n << 1) + 1
            aux *= aux
            for k in xrange(aux, end, 2 * aux):
                sieve[k >> 1] = False
 
    s  = int(sqrt(end)) + 1

src/h/e/hedge-0.91/examples/maxwell/analytic_solutions.py   hedge(Download)
from hedge.tools import \
        cyl_bessel_j, \
        cyl_bessel_j_prime
from math import sqrt, pi, sin, cos, atan2
import cmath
 
 
    def __call__(self, x, el):
        xy = x[:2]
        r = sqrt(xy*xy)
        phi = atan2(x[1], x[0])
 
        prev_result = self.adaptee(x, el)
        result = []
 
        x_mn = bessel_zeros[m][n-1]
 
        self.omega = 1 / sqrt(mu*epsilon) * sqrt(
                x_mn**2 / R**2
                + p**2 * pi**2 / d**2)
 
    def __call__(self, x, el):
        # coordinates -----------------------------------------------------
        xy = x[:2]
        r = sqrt(xy*xy)
        phi = atan2(x[1], x[0])
        z = x[2]
 
 
        self.factors = [n*pi/a for n,  a in zip(self.mode_indices, self.dimensions)]
 
        c = 1/sqrt(mu*epsilon)
        self.k = sqrt(sum(f**2 for f in self.factors))
        self.omega = self.k*c
 
        def l2_norm(field):
            return sqrt(dot(field, mass*field))
 
        base_l2 = l2_norm(base)
        err_l2 = l2_norm(err)
        if base_l2 == 0:
            if err_l2 == 0:

src/s/h/shedskin-HEAD/examples/mao.py   shedskin(Download)
Original version of AO bench was written by Syoyo Fujita. The original code(Proce55ing version) is licensed under BSD3 license. You can freely modify, port and distribute AO bench
'''
 
from math import sqrt, sin, cos, fabs
import random
from array import array
 
def vnormalize(c):
    length = sqrt(vdot(c, c))
 
    if fabs(length) > 1.0e-17:
        c.x /= length
        c.y /= length
        c.z /= length
    D = B * B - C
 
    if D > 0.0:
        t = -B - sqrt(D)
        if t > 0.0:
            if t < isect.t:
                isect.t = t
 
    for j in xrange(ntheta):
        for i in xrange(nphi):
            theta = sqrt(random.random())
            phi = 2.0 * 3.14159265358979323846 * random.random()
 
            x = cos(phi) * theta
            y = sin(phi) * theta
            z = sqrt(1.0 - theta * theta)

src/s/h/shedskin-HEAD/examples/ml/surfacepoint.py   shedskin(Download)
#  MiniLight Python : minimal global illumination renderer
#
#  Copyright (c) 2007-2008, Harrison Ainsworth / HXA7241 and Juraj Sukop.
#  http://www.hxa7241.org/
 
 
from math import cos, pi, sin, sqrt
    def get_next_direction(self, in_direction):
        reflectivity_mean = self.triangle_ref.reflectivity.dot(ONE) / 3.0
        if random() < reflectivity_mean:
            color = self.triangle_ref.reflectivity * (1.0 / reflectivity_mean)
            _2pr1 = pi * 2.0 * random()
            sr2 = sqrt(random())
            x = (cos(_2pr1) * sr2)
            y = (sin(_2pr1) * sr2)
            z = sqrt(1.0 - (sr2 * sr2))

src/s/u/surukuku-HEAD/trunk/Samples/OpenGL/gears.py   surukuku(Download)
from OpenGL.GL import *
from OpenGL.GLUT import *
import sys, time
from math import sin,cos,sqrt,pi
 
def gear(inner_radius, outer_radius, width, teeth, tooth_depth):
    r0 = inner_radius
        glVertex3f(r1*cos(angle), r1*sin(angle), -width*0.5)
        u = r2*cos(angle+da) - r1*cos(angle)
        v = r2*sin(angle+da) - r1*sin(angle)
        len = sqrt(u*u + v*v)
        u = u / len
        v = v / len
        glNormal3f(v, -u, 0.0)

src/p/y/python-opengles-HEAD/examples/gears.py   python-opengles(Download)
import egl
from gles import *
import time
from math import sin,cos,sqrt,pi
 
def float2fixed(values):
  ret = tuple([int(v*pow(2,16)) for v in values])
        v2 = float2fixed((r1*cos(angle), r1*sin(angle), -width*0.5))
        u = r2*cos(angle+da) - r1*cos(angle)
        v = r2*sin(angle+da) - r1*sin(angle)
        len = sqrt(u*u + v*v)
        u = u / len
        v = v / len
 

src/s/u/surukuku-HEAD/Samples/OpenGL/gears.py   surukuku(Download)
from OpenGL.GL import *
from OpenGL.GLUT import *
import sys, time
from math import sin,cos,sqrt,pi
 
def gear(inner_radius, outer_radius, width, teeth, tooth_depth):
    r0 = inner_radius
        glVertex3f(r1*cos(angle), r1*sin(angle), -width*0.5)
        u = r2*cos(angle+da) - r1*cos(angle)
        v = r2*sin(angle+da) - r1*sin(angle)
        len = sqrt(u*u + v*v)
        u = u / len
        v = v / len
        glNormal3f(v, -u, 0.0)

src/n/u/numeric-for-engineer-HEAD/example6_7.py   numeric-for-engineer(Download)
## example6_7
from math import cos,sqrt,pi
from romberg import *
 
def f(x): return 2.0*(x**2)*cos(x**2)
 
I,n = romberg(f,0,sqrt(pi))

src/n/u/numeric-for-engineer-HEAD/example6_4.py   numeric-for-engineer(Download)
## example6_4
from math import sqrt,cos,pi
from trapezoid import *
 
def f(x): return sqrt(x)*cos(x)
 
Iold = 0.0

src/l/e/Levmar-HEAD/examples/curvefit_psdvoigt.py   Levmar(Download)
and 3 for the lower and upper bound respectively, the third has only the
upper bound of 10, and the fourth has to be greater than or equal to 0.
"""
from math import (log, sqrt, pi,)
import numpy as np
import levmar
 
def psd_voigt(p, x):
    peak, xc, w, m, const = p
    g = sqrt(__4ln2/pi)/w * np.exp(-__4ln2*((x-xc)/w)**2)
    l = 2/(pi*w) / (1 + 4*((x-xc)/w)**2)
    c = (1-m) * sqrt(__4ln2/pi)/w + m * 2/(pi*w)
    return peak * (((1-m)*g + m*l) / c) + const
 

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next