Пример #1
0
def testjac(dpsv, nv, av, bv, epsv):
    print ">>>>>> r_jacobi(n,a,b)"
    print "{0:>4s} {1:>4s} {2:>4s} {3:>4s} {4:>10s} {5:>15s} {6:>10s} {7:>10s}".\
          format("n", "a", "b", "dps", "eps",  "errmaxnorm", "tg", "ts")

    for ni,ai,bi,dpsi,epsi in product(nv,av,bv,dpsv,epsv):
        mp.dps = dpsi
        
        # Compute using the closed form
        ab = r_jacobi(ni,ai,bi)
        
        # Calculate Gauss quadrature rules
        t1 = time.time()
        xw = gauss(ab)
        t2 = time.time()
        
        # Invoke the Stieltjes algorithm to calculate ab again
        t3 = time.time()
        ab1 = dsti(xw)
        t4 = time.time()
        
        err = norm(ab-ab1, inf)
        
        print "{0:>4d} {1:>4s} {2:>4s} {3:>4d} {4:>10s} {5:>15s}  {6:>10f} {7:>10f}".format(\
            ni, nstr(ai), nstr(bi), dpsi, nstr(epsi), nstr(err), t2-t1, t4-t3)
Пример #2
0
def randomize_time(mean):
  allowed_range = mean * STDEV
  stdev = allowed_range / 3  # 99.73% chance to be in the allowed range

  t = 0
  while abs(mean - t) > allowed_range:
    t = gauss(mean, stdev)

  return t
Пример #3
0
def _do_inversion(com, rws):
    """
    Print formatting messages and call gauss elimination
    :param com: communicator
    :param rws: rows
    :return: inversed rows
    """
    print(formatting(com.rank, format_action('receive', rows=rws)))

    inv = gauss(np.array(rws, dtype=np.float64), com, n)

    print(formatting(com.rank, format_action('inverse', rows=inv)))

    return inv
def polynomialInterpolation(x1, x2, x3, dx0, dx1):
    '''Given three one dimension points and the curve's derivative vectors of start and end points,
calculate a four order polynomial curve(x = n4*t^4 + n3*t^3 + n2*t^2 + n1*t + n0) based on t = [0, 0.5, 1],
[x1, x2, x3] <=> t=[0, 0.5, 1]
[dx0, dx1] <=> t = [0, 1]
return polynomial coefficients c = [n4, n3, n2, n1, n0]
	'''
    b = np.array([x3, x2, dx1, dx0, x1], dtype=np.float)
    #np.array() <=> np.matrix()
    A = np.array( [[1, 1, 1, 1, 1],\
      [0.5**4, 0.5**3, 0.5**2, 0.5, 1],\
      [4, 3, 2, 1, 0],\
      [0, 0, 0, 1, 0],\
      [0, 0, 0, 0, 1]], dtype = np.float)
    x = gauss(A, b)
    return x
Пример #5
0
print ">>>> gauss"

dpsv = [5, 15, 50]
nv = [10, 20]
av = [mpf(1)]
bv = [mpf(1)]
epsv = [mpf(1e-5), mpf(1e-15), mpf(1e-50)]

#testjac(dpsv,nv,av,bv,epsv)

n=5
kappa = 1
ab = r_jacobi(n,0,0)
p = ab_to_poly(ab)
xw = gauss(ab)

els = uniform_els(-1,1,3)
print els
fea_diri2(els, kappa, 0, xw)

quit()

from pylab import *
xx = arange(-1.0, 1.0, 0.01)
for i in range(n):
    plot(xx,polyvalv(p[i,:],xx))
axis([-1,1,-0.5,0.5])
grid(True)
show()
Пример #6
0
def lognormal(x, mean, sigma):
    l = log10(x)
    mean = log10(mean)
    val = gauss(l, mean, sigma)
    return val
Пример #7
0
#!usr/bin/env python
from auxFuncSLE import *
from gauss import *
from gaussJordan import *

piv = 2

A = [[2.11, -4.21, 0.921], [4.01, 10.2, -1.12], [1.09, 0.987, 0.832]]

b = [2.01, -3.09, 4.21]

# gauss
print "\nMetodo Gauss Jordan"
X = gauss(A, b, piv)
print X
# gauss Jordan
print "\nMetodo Gauss Jordan"
X = gaussJordan(A, b, piv)
print X
print
Пример #8
0
def gauss_main():
    matrix = [[0.10, 12, -0.13, 0.10], [0.12, 0.71, 0.15, 0.26],
              [-0.13, 0.15, 0.63, 0.38]]

    x = gauss(3, matrix)
    print(x)