Esempio n. 1
0
def to909090(gr):
    """
    Reduce a grain in the full range angules to 90x90x90 cube
    """

    # if gr[0]<0.:
    #     gr[0] = 360 + gr[0]

    from sym import __mmm__ as mmm
    from sym import cubic
    sam = mmm() # orthorhombic sample symmetry
    crm = cubic() # cubic crystal symmetry

    a = euler(ph=gr[0], th=gr[1], tm=gr[2], echo=False) # ca<-sa
    mats = []
    newa = []
    for i in range(len(sam)):
        dum = np.dot(a, sam[i].T) # ca<-sa H
        for j in range(len(crm)):
            nnewa = np.dot(crm[j], dum)  # H_ca ca<-sa H_sa
            mats.append(nnewa)

    #print len(mats)

    eul_angs = []
    n = 0 
    for i in range(len(mats)):
        angs = euler(a=mats[i], echo=False)
        if all(angs[k]<=90. for k in range(3)) and \
           all(angs[k]>=0.  for k in range(3)):
            n = n + 1
            #print angs
            eul_angs.append(angs)

    temp_gr = []
    for i in range(len(eul_angs)):
        temp_gr.append([eul_angs[i][0],
                       eul_angs[i][1],
                       eul_angs[i][2]])

    temp_gr = np.around(temp_gr, decimals=3)
        
    temp_gr = unique2d(np.array(temp_gr))

    new_gr = []
    for i in range(len(temp_gr)):
        dgr = [temp_gr[i][0],temp_gr[i][1],temp_gr[i][2],gr[-1]/len(temp_gr)]
        new_gr.append(dgr)
    return np.array(new_gr)
Esempio n. 2
0
def Punto_1():
    punto_inicio = 0  # s
    punto_final = longitud / velocidad  # s
    resolucion_euler = euler(funcion_sin_radiacion, cadencia, punto_inicio,
                             punto_final, T_0)
    resolucion_runge_kutta = runge_kutta(funcion_sin_radiacion, cadencia,
                                         punto_inicio, punto_final, T_0)
    resultados_reales = calcular_resultados_reales(solucion_sin_radiacion,
                                                   cadencia, punto_inicio,
                                                   punto_final)

    guardar_grafico_tiempo_vs_temperatura("Método Euler", resultados_reales,
                                          "Solución Analítica",
                                          resolucion_euler, "Euler")
    guardar_grafico_tiempo_vs_temperatura("Método Runge-Kutta",
                                          resultados_reales,
                                          "Solución Analítica",
                                          resolucion_runge_kutta,
                                          "Runge-Kutta")

    error_relativo_euler = calcular_error_relativo(resultados_reales,
                                                   resolucion_euler)
    error_relativo_runge_kutta = calcular_error_relativo(
        resultados_reales, resolucion_runge_kutta)

    guardar_grafico_error_relativo("Error Relativo Euler",
                                   error_relativo_euler)
    guardar_grafico_error_relativo("Error Relativo Runge-Kutta",
                                   error_relativo_runge_kutta)
Esempio n. 3
0
def createTable(eq, approximation, left, right, h):
    func = f1
    picard = picard1
    if (eq.get_pow_x() == 2):
        func = f2
        picard = picard2

    table = PrettyTable()
    table.field_names = [
        "X", "Picard method", "Explicit Euler method",
        "Unexplicit Euler method", "Runge-Kutta method"
    ]
    yp_eulerExp = 0
    yp_euler = 0
    yp_runge = 0
    x = left
    while x <= right:
        print("\rprocessing...{:.0f}%".format((x * 100) / right), end="\n")
        yp_eulerExp = euler_explicit(yp_eulerExp, x, h, func)
        yp_euler = euler(yp_euler, x, h, func)
        yp_runge = rungeKuttaSecOrder(yp_runge, x, h, func)
        if (x + h > right):
            table.add_row([
                "{:.1f}".format(x),
                "{:.4f}".format(0)  #picard(x, approximation))
                ,
                "{:.4f}".format(yp_eulerExp),
                "{:.4f}".format(yp_euler),
                "{:.4f}".format(yp_runge)
            ])
        x += h

    print("Table for Y' = ", eq.equation, " equation")
    print(table)
Esempio n. 4
0
def rsa(n, p, M, e) : 
	""" Crypte le message par le RSA avec les parametres n, p et e """
	N = n * p
	#print "N : " + str(N)
	phiN = euler(N)
	#print "phiN : " + str(phiN)
	d = inverse(e, phiN)
	#d = d + phiN
	#print "d : " + str(d)
	M2 = restexpmn(M, e, N)
	return M2
Esempio n. 5
0
def spread(eul=None, w=None, nseg=0):
    """
    Given the the Euler angle set (including the volume),
    spread the current angle into nseg number of poles
    based on a distribution with the scatter angle is given as w

    eul = [ph1, ph, ph2, vf]
    """
    rst = []

    vf = eul[3] / nseg
    a = euler(ph = eul[0], th = eul[1], tm = eul[2], echo=False)
    for i in range(nseg):

        ## Generate a random rotation axis, about which the given grain rotates
        delta, phi = rot_axis()

        ## Calculates the spread (rotation) matrix b
        b = spread_matrix(
            delta, phi,
            gaussian(w))
        ## Rotates the rotation matrix a

        c = np.zeros((3,3))
        for i in range(3):
            for j in range(3):
                for m in range(3):
                    c[i,j] = c[i,j] + b[m,i] * a[m,j]
                    pass
                pass
            pass
        #c = np.dot(b.transpose(), a)

        p1, p, p2 = euler(a=c, echo=False)

        rst.append([p1, p, p2, vf])

        pass

    ## Returns the spread angle sets
    return rst
Esempio n. 6
0
File: e82.py Progetto: Sudoka/Euler
def main():
  e = euler()
  M = [map(int, line[:-1].split(','))for line in open('matrix.txt', 'r')]
  S = [[0 for i in xrange(len(M[0]))] for j in xrange(len(M))]
  for i in xrange(len(M)):
    S[i][0] = M[i][0]
  S[-1][1] = S[-1][0]+M[-1][1]
  S[0][1] = S[0][0]+M[0][1] 

  for k in xrange(1):
    for i in xrange(len(M)):
      for j in xrange(1, len(M[0])):
        if i+1 == len(M):
          S[i][j] = M[i][j] + min(S[i-1][j], S[i][j-1])
        elif i-1 < 0:
          S[i][j] = M[i][j] + min(S[i+1][j], S[i][j-1])
        else:
          S[i][j] = M[i][j] + min(S[i-1][j], S[i+1][j], S[i][j-1])
  print min([row[-1] for row in S])
Esempio n. 7
0
def main():
    e = euler()
    M = [map(int, line[:-1].split(',')) for line in open('matrix.txt', 'r')]
    S = [[0 for i in xrange(len(M[0]))] for j in xrange(len(M))]
    for i in xrange(len(M)):
        S[i][0] = M[i][0]
    S[-1][1] = S[-1][0] + M[-1][1]
    S[0][1] = S[0][0] + M[0][1]

    for k in xrange(1):
        for i in xrange(len(M)):
            for j in xrange(1, len(M[0])):
                if i + 1 == len(M):
                    S[i][j] = M[i][j] + min(S[i - 1][j], S[i][j - 1])
                elif i - 1 < 0:
                    S[i][j] = M[i][j] + min(S[i + 1][j], S[i][j - 1])
                else:
                    S[i][j] = M[i][j] + min(S[i - 1][j], S[i + 1][j],
                                            S[i][j - 1])
    print min([row[-1] for row in S])
from euler import *
import matplotlib.pyplot as plt

h = 0.01
t = 100

pa = np.array([0, 0])
ve = np.array([2, 3])
ac = np.array([0, -10])  #gravedad

# Ejercicio
plt.figure()
vp, vv, va, pt = euler(pa, ve, ac, t, h)

vpp = []
for p in vp:
    if p[1] < -0.05:
        break
    vpp.append(p)
vp = npa(vpp)

plt.plot(vp[:, 0], vp[:, 1])
plt.xlabel('x')
plt.ylabel('y')
plt.title('x-y')
plt.grid(True)
plt.show()
Esempio n. 9
0
        if p[1] <= 0:
            break
        vpp.append(p)
    return npa(vpp)


h = 0.01
t = 100

pa = np.array([0, 0, 0])
ve = np.array([5, 2, 0])
ac = np.array([0, -10, 0])  #gravedad

# Ejercicio
fig = plt.figure()
vp, vv, va, pt = euler(pa, ve, ac, t, h)
ac = np.array([2, -10, 0])  #gravedad
vp1, vv1, va1, pt1 = euler(pa, ve, ac, t, h)
ac = np.array([-1, -10, 0])  #gravedad
vp2, vv2, va2, pt2 = euler(pa, ve, ac, t, h)
ac = np.array([2, -10, -1])  #gravedad
vp3, vv3, va3, pt3 = euler(pa, ve, ac, t, h)
ac = np.array([pow(100, 2) / 5, -10, 0])  #gravedad
vp4, vv4, va4, pt4 = euler(pa, ve, ac, t, h)

vp1 = limit(vp1)
ax = fig.add_subplot(2, 2, 1, projection='3d')
ax.plot(vp1[:, 0], vp1[:, 2], vp1[:, 1])
ax.scatter3D([vp1[0, 0]], [vp1[0, 2]], [vp[0, 1]], color="red")
ax.scatter3D([vp1[len(vp1) - 1, 0]], [vp1[len(vp1) - 1, 2]],
             [vp[len(vp1) - 1, 1]],
Esempio n. 10
0
from euler import *
import matplotlib.pyplot as plt

h = 0.1
t = 10

a = -10  #gravedad

# Ejercicio
vp, vv, va, pt = euler(-30, -30, a, t, h)

DrawT_E(plt, pt, vp)
DrawT_V(plt, pt, vv)
DrawT_A(plt, pt, va)
DrawE_V(plt, vp, vv)
plt.show()

vp, vv, va, pt = euler(0, 0, a, t, h)
DrawT_E(plt, pt, vp)
DrawT_V(plt, pt, vv)
DrawT_A(plt, pt, va)
DrawE_V(plt, vp, vv)
plt.show()

vp, vv, va, pt = euler(30, 30, a, t, h)
DrawT_E(plt, pt, vp)
DrawT_V(plt, pt, vv)
DrawT_A(plt, pt, va)
DrawE_V(plt, vp, vv)
plt.show()
Esempio n. 11
0
	def test_euler1(self) :
		resultat = euler(1500)
		self.assertEqual(resultat, 400)
Esempio n. 12
0
	def test_euler5(self) :
		resultat = euler(euler(1500))
		self.assertEqual(resultat, 160)
Esempio n. 13
0
	def test_euler2(self) :
		resultat = euler(120)
		self.assertEqual(resultat, 32)
Esempio n. 14
0
def main():
  e = euler()
  print e.primes(100)
Esempio n. 15
0
kc = np.zeros(nt+1)
rw = np.zeros(nt+1)
rs = np.zeros(nt+1)
   
clock_time_init = tm.time()

i = np.arange(1,nx)
j = np.arange(1,ny)
ii,jj = np.meshgrid(i,j, indexing='ij')

for k in range(nt+1):
    w0 = np.copy(w)
    s0 = np.copy(s)
    
    if its == 1:    
        w,s = euler(nx,ny,dx,dy,dt,re,w,s,ii,jj,input_data,bc,bc3)
    elif its == 2:
        w,s = rk3(nx,ny,dx,dy,dt,re,w,s,ii,jj,input_data,bc,bc3)

    kc[k] = k
    rw[k] = np.linalg.norm(w - w0)/np.sqrt(np.size(w))
    rs[k] = np.linalg.norm(s - s0)/np.sqrt(np.size(s))
#    
    if k % freq == 0:
        print('%0.3i %0.3e %0.3e' % (kc[k], rw[k], rs[k]))

    if rw[k] <= eps and rs[k] <= eps:
        break

kc = kc[:k+1]
rw = rw[:k+1]
Esempio n. 16
0
from euler import *
import matplotlib.pyplot as plt

h=0.05
t=20

a = 10 #gravedad

# Ejercicio
plt.figure()
vp,vv,va,pt = euler(-20,15,a,t,h,resta);
DrawT_E(plt,pt,vp)
DrawT_V(plt,pt,vv)
DrawT_A(plt,pt,va)
DrawE_V(plt,vp,vv)
plt.show()

plt.figure()
vp,vv,va,pt = euler(-20,0,a,t,h,resta);
DrawT_E(plt,pt,vp)
DrawT_V(plt,pt,vv)
DrawT_A(plt,pt,va)
DrawE_V(plt,vp,vv)
plt.show()

plt.figure()
vp,vv,va,pt = euler(20,-15,a,t,h,resta);
DrawT_E(plt,pt,vp)
DrawT_V(plt,pt,vv)
DrawT_A(plt,pt,va)
DrawE_V(plt,vp,vv)
Esempio n. 17
0
	def test_euler4(self) :
		resultat = euler(59)
		self.assertEqual(resultat, 58)
Esempio n. 18
0
            sw, sb = alphaw, alphab
            # Planetary albedo
            planet_albedo = albedo(alphaw, alphab, alphag, aw, ab, ag)
            # Planetary temperature
            T = planetary_temp(S, planet_albedo, L=L)
            # Local temperature
            Tw = local_temp(planet_albedo, aw, T)
            Tb = local_temp(planet_albedo, ab, T)
            # Birth rate
            betaw = beta(Tw)
            betab = beta(Tb)
            # Change in daisies
            dawdt = daisy_replicator(alphaw, alphag, betaw, gamma)
            dabdt = daisy_replicator(alphab, alphag, betab, gamma)
            # Integrate
            alphaw = euler(alphaw, dawdt)
            alphab = euler(alphab, dabdt)
            alphag = p - alphaw - alphab
            n += 1
        # Store the output
        alphaw_out[i] = alphaw
        alphab_out[i] = alphab
        temp_out[i] = T

# Plot the results
# Cover fractions
white = plt.plot(luminosities, alphaw_out * 100, 'b', label='White')
black = plt.plot(luminosities, alphab_out * 100, 'k', label='Black')
plt.legend(loc='upper right')
plt.xlabel('Luminosity')
plt.ylabel('Surface cover %')