Homogeneous Gas

Here is a notebook for homogeneous gas model.

Here we are talking about a homogeneous gas bulk of neutrinos with single energy. The EoM is $$ i \partial_t \rho_E = \left[ \frac{\delta m^2}{2E}B +\lambda L +\sqrt 2 G_F \int_0^\infty dE' ( \rho_{E'} - \bar \rho_{E'} ) ,\rho_E \right] $$

while the EoM for antineutrinos is $$ i \partial_t \bar\rho_E = \left[- \frac{\delta m^2}{2E}B +\lambda L +\sqrt 2 G_F \int_0^\infty dE' ( \rho_{E'} - \bar \rho_{E'} ) ,\bar\rho_E \right] $$

Initial: Homogeneous, Isotropic, Monoenergetic $\nu_e$ and $\bar\nu_e$

The equations becomes $$ i \partial_t \rho_E = \left[ \frac{\delta m^2}{2E} B +\lambda L +\sqrt 2 G_F ( \rho_{E} - \bar \rho_{E} ) ,\rho_E \right] $$ $$ i \partial_t \bar\rho_E = \left[- \frac{\delta m^2}{2E}B +\lambda_b L +\sqrt 2 G_F ( \rho_{E} - \bar \rho_{E} ) ,\bar\rho_E \right] $$

Define $\omega=\frac{\delta m^2}{2E}$, $\omega = \frac{\delta m^2}{-2E}$, $\mu=\sqrt{2}G_F n_\nu$ $$ i \partial_t \rho_E = \left[ \omega B +\lambda L +\mu ( \rho_{E} - \bar \rho_{E} ) ,\rho_E \right] $$ $$ i \partial_t \bar\rho_E = \left[\bar\omega B +\bar\lambda L +\mu ( \rho_{E} - \bar \rho_{E} ) ,\bar\rho_E \right] $$

where

$$ B = \frac{1}{2} \begin{pmatrix} -\cos 2\theta_v & \sin 2\theta_v \\ \sin 2\theta_v & \cos 2\theta_v \end{pmatrix} = \begin{pmatrix} -0.38729833462 & 0.31622776601\\ 0.31622776601 & 0.38729833462 \end{pmatrix} $$$$ L = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} $$

Initial condition $$ \rho(t=0) = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} $$

$$ \bar\rho(t=0) =\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} $$

define the following quantities

  1. hbar$=\hbar$
  2. delm2E$= \delta m^2/2E$
  3. lamb $= \lambda$, lambb $= \bar\lambda$
  4. gF $= G_F$
  5. mu $=\mu$
  6. omega $=\omega$, omegab $=\bar\omega$

Numerical


In [305]:
# This line configures matplotlib to show figures embedded in the notebook, 
# instead of opening a new window for each figure. More about that later. 
# If you are using an old version of IPython, try using '%pylab inline' instead.
%matplotlib inline
%load_ext snakeviz

import numpy as np
from scipy.optimize import minimize
from scipy.special import expit
import matplotlib.pyplot as plt

from matplotlib.lines import Line2D

import timeit

import pandas as pd

import plotly.plotly as py
from plotly.graph_objs import *
import plotly.tools as tls


The snakeviz extension is already loaded. To reload it, use:
  %reload_ext snakeviz

In [306]:
# hbar=1.054571726*10**(-34)
hbar=1
delm2E=1
lamb=1  ## lambda for neutrinos
lambb=1 ## lambda for anti neutrinos
gF=1
nd=1  ## number density
ndb=1   ## number density
omega=1
omegab=1

## Here are some matrices to be used

elM = np.array([[1,0],[0,0]])
bM = 1/2*np.array( [ [ - 0.38729833462,0.31622776601] , [0.31622776601,0.38729833462] ] )

## sqareroot of 2
sqrt2=np.sqrt(2)

Using Mathematica, I can find the 4*2 equations


In [307]:
#r11prime(t)

## The matrix eqn for neutrinos. Symplify the equation to the form A.X=0. Here I am only writing down the LHS.
## Eqn for r11'
# 1/2*( r21(t)*( bM12*delm2E - 2*sqrt2*gF*rb12(t) ) + r12(t) * ( -bM21*delm2E + 2*sqrt2*gF*rb21(t) ) - 1j*r11prime(t)  )
## Eqn for r12'
# 1/2*( r22(t)* ( bM12 ) )

### wait a minute I don't actually need to write down this. I can just do this part in numpy.

I am going to substitute all density matrix elements using their corrosponding network expressions.

So first of all, I need the network expression for the unknown functions.

A function is written as

$$ y_i= 1+t_i v_k f(t_i w_k+u_k) ,$$

while it's derivative is

$$v_k f(t w_k+u_k) + t v_k f(tw_k+u_k) (1-f(tw_k+u_k)) w_k .$$

Now I can write down the equations using these two forms.


In [308]:
def trigf(x):
    #return 1/(1+np.exp(-x)) # It's not bad to define this function here for people could use other functions other than expit(x).
    return expit(x)

In [ ]:


In [309]:
## The time derivative part

### Here are the initial conditions

init = np.array( [[1,0],[0,0]] )
initb = np.array([[0,0],[0,0]])

### For neutrinos

def rho(x,ti,initialCondition): # x is the input structure arrays, ti is a time point

    v11,w11,u11,v12,w12,u12,v21,w21,u21,v22,w22,u22 = np.split(x,12)[:12]
        
    elem11= np.sum(ti * v11 * trigf( ti*w11 +u11 ) )
    elem12= np.sum(ti * v12 * trigf( ti*w12 +u12 ) )
    elem21= np.sum(ti * v21 * trigf( ti*w21 +u21 ) )
    elem22= np.sum(ti * v22 * trigf( ti*w22 +u22 ) )
    
    return initialCondition + np.array([[ elem11 , elem12 ],[elem21, elem22]])

def rhob(xb,ti,initialConditionb): # x is the input structure arrays, ti is a time point

    vb11,wb11,ub11,vb12,wb12,ub12,vb21,wb21,ub21,vb22,wb22,ub22 = np.split(xb,12)[:12]

    elem11= np.sum(ti * vb11 * trigf( ti*wb11 +ub11 ) )
    elem12= np.sum(ti * vb12 * trigf( ti*wb12 +ub12 ) )
    elem21= np.sum(ti * vb21 * trigf( ti*wb21 +ub21 ) )
    elem22= np.sum(ti * vb22 * trigf( ti*wb22 +ub22 ) )
    
    return initialConditionb + np.array([[ elem11 , elem12 ],[elem21, elem22]])

In [310]:
## Test
xtemp=np.ones(120)
rho(xtemp,1,init)


Out[310]:
array([[ 9.80797078,  8.80797078],
       [ 8.80797078,  8.80797078]])

In [311]:
## Define Hamiltonians for both

def hamil(x,xb,ti,initialCondition,initialConditionb):
    
    return delm2E*bM + lamb*elM + sqrt2*gF*( rho(x,ti,initialCondition) - rhob(xb,ti,initialConditionb) )


def hamilb(x,xb,ti,initialCondition,initialConditionb):
    
    return -delm2E*bM + lambb*elM + sqrt2*gF*( rho(x,ti,initialCondition) - rhob(xb,ti,initialConditionb) )

In [312]:
## The commutator

def comm(x,xb,ti,initialCondition,initialConditionb):
    
    return np.dot(hamil(x,xb,ti,initialCondition,initialConditionb), rho(x,ti,initialCondition) ) - np.dot(rho(x,ti,initialCondition), hamil(x,xb,ti,initialCondition,initialConditionb) )

def commb(x,xb,ti,initialCondition,initialConditionb):
    
    return np.dot(hamilb(x,xb,ti,initialCondition,initialConditionb), rhob(xb,ti,initialConditionb) ) - np.dot(rhob(xb,ti,initialConditionb), hamilb(x,xb,ti,initialCondition,initialConditionb) )

In [313]:
## Test

print "neutrino\n",comm(xtemp,xtemp,1,init,initb)
print "antineutrino\n",commb(xtemp,xtemp,0.5,init,initb)


neutrino
[[  0.          21.26432251]
 [-21.26432251   0.        ]]
antineutrino
[[ 0.          9.86899694]
 [-9.86899694  0.        ]]

In [314]:
## The COST of the eqn set

def costTi(x,xb,ti,initialCondition,initialConditionb):
    
    v11,w11,u11,v12,w12,u12,v21,w21,u21,v22,w22,u22 = np.split(x,12)[:12]
    vb11,wb11,ub11,vb12,wb12,ub12,vb21,wb21,ub21,vb22,wb22,ub22 = np.split(xb,12)[:12]
    
    fvec11 = np.array(trigf(ti*w11 + u11) )  # This is a vector!!!
    fvec12 = np.array(trigf(ti*w12 + u12) )
    fvec21 = np.array(trigf(ti*w21 + u21) )
    fvec22 = np.array(trigf(ti*w22 + u22) )
    
    fvecb11 = np.array(trigf(ti*wb11 + ub11) )  # This is a vector!!!
    fvecb12 = np.array(trigf(ti*wb12 + ub12) )
    fvecb21 = np.array(trigf(ti*wb21 + ub21) )
    fvecb22 = np.array(trigf(ti*wb22 + ub22) )
    
    
    costi11= ( np.sum (v11*fvec11 + ti * v11* fvec11 * ( 1 -  fvec11  ) * w11 ) + 1j*  ( comm(x,xb,ti,initialCondition,initialConditionb)[0,0] )  )  
    costi12= ( np.sum (v12*fvec12 + ti * v12* fvec12 * ( 1 -  fvec12  ) * w12 ) + 1j*  ( comm(x,xb,ti,initialCondition,initialConditionb)[0,1] )  )  
    costi21= ( np.sum (v21*fvec21 + ti * v21* fvec21 * ( 1 -  fvec21  ) * w21 ) + 1j*  ( comm(x,xb,ti,initialCondition,initialConditionb)[1,0] )  )  
    costi22= ( np.sum (v22*fvec22 + ti * v22* fvec22 * ( 1 -  fvec22  ) * w22 ) + 1j*  ( comm(x,xb,ti,initialCondition,initialConditionb)[1,1] )  )  

    costbi11= ( np.sum (vb11*fvecb11 + ti * vb11* fvecb11 * ( 1 -  fvecb11  ) * wb11 ) + 1j*  ( commb(x,xb,ti,initialCondition,initialConditionb)[0,0] )  )  
    costbi12= ( np.sum (vb12*fvecb12 + ti * vb12* fvecb12 * ( 1 -  fvecb12  ) * wb12 ) + 1j*  ( commb(x,xb,ti,initialCondition,initialConditionb)[0,1] )  )  
    costbi21= ( np.sum (vb21*fvecb21 + ti * vb21* fvecb21 * ( 1 -  fvecb21  ) * wb21 ) + 1j*  ( commb(x,xb,ti,initialCondition,initialConditionb)[1,0] )  )  
    costbi22= ( np.sum (vb22*fvecb22 + ti * vb22* fvecb22 * ( 1 -  fvecb22  ) * wb22 ) + 1j*  ( commb(x,xb,ti,initialCondition,initialConditionb)[1,1] )  )  
    
    return (np.real(costi11))**2 + (np.real(costi12))**2+ (np.real(costi21))**2 +  (np.real(costi22))**2 + (np.real(costbi11))**2 + (np.real(costbi12))**2 +(np.real(costbi21))**2 + (np.real(costbi22))**2 + (np.imag(costi11))**2 + (np.imag(costi12))**2+ (np.imag(costi21))**2 +  (np.imag(costi22))**2 + (np.imag(costbi11))**2 + (np.imag(costbi12))**2 +(np.imag(costbi21))**2 + (np.imag(costbi22))**2

In [315]:
costTi(xtemp,xtemp,0,init,initb)


Out[315]:
427.55731631081869

In [316]:
## Calculate the total cost

def cost(xtot,t,initialCondition,initialConditionb):
    
    x,xb = np.split(xtot,2)[:2]

    t = np.array(t)
    
    costTotal = np.sum( costTList(x,xb,t,initialCondition,initialConditionb)  )
        
    return costTotal
    

def costTList(x,xb,t,initialCondition,initialConditionb):  ## This is the function WITHOUT the square!!! 
        
    t = np.array(t)
    
    costList = np.asarray([])
    
    for temp in t:
        tempElement = costTi(x,xb,temp,initialCondition,initialConditionb)
        costList = np.append(costList, tempElement)
        
    return np.array(costList)

In [317]:
ttemp = np.linspace(0,10)
print ttemp


[  0.           0.20408163   0.40816327   0.6122449    0.81632653
   1.02040816   1.2244898    1.42857143   1.63265306   1.83673469
   2.04081633   2.24489796   2.44897959   2.65306122   2.85714286
   3.06122449   3.26530612   3.46938776   3.67346939   3.87755102
   4.08163265   4.28571429   4.48979592   4.69387755   4.89795918
   5.10204082   5.30612245   5.51020408   5.71428571   5.91836735
   6.12244898   6.32653061   6.53061224   6.73469388   6.93877551
   7.14285714   7.34693878   7.55102041   7.75510204   7.95918367
   8.16326531   8.36734694   8.57142857   8.7755102    8.97959184
   9.18367347   9.3877551    9.59183673   9.79591837  10.        ]

In [318]:
ttemp = np.linspace(0,10)
print costTList(xtemp,xtemp,ttemp,init,initb)
print cost(xtemp,ttemp,init,initb)


[    427.55731631     576.4910937      853.37726656    1282.49988421
    1884.10392755    2673.91751306    3663.20708292    4859.23007651
    6265.9208822     7884.65985964    9715.0132345    11755.37565319
   14003.48530838   16456.80879099   19112.80902104   21969.11701801
   25023.62977467   28274.5546376    31720.41721704   35360.04611511
   39192.54430487   43217.25409161   47433.72030466   51841.65465775
   56440.90298664   61231.41622272   66213.22539729   71386.4206155
   76751.13372951   82307.52433125   88055.76864167   93996.05087228
  100128.55665759  106453.46819441  112970.96076627  119681.20037537
  126584.34224643  133680.53000561  140969.89537205  148452.5582301
  156128.62697564  163998.19905246  172061.36161212  180318.1922465
  188768.75975409  197413.12491109  206251.3412265   215283.45566646
  224509.50933817  233929.53812735]
987353.364647

In [ ]:

Minimization

Here is the minimization


In [373]:
tlin = np.linspace(0,0.5,3)
initGuess = np.ones(120)
# initGuess = np.random.rand(1,30)+2

costF = lambda x: cost(x,tlin,init,initb)

In [374]:
cost(initGuess,tlin,init,initb)


Out[374]:
520.15036612564302

In [375]:
## %%snakeviz
# startCG = timeit.default_timer()
#costFResultCG = minimize(costF,initGuess,method="CG")
#stopCG = timeit.default_timer()

#print stopCG - startCG

#print costFResultCG

In [376]:
%%snakeviz
startSLSQP = timeit.default_timer()
costFResultSLSQP = minimize(costF,initGuess,method="SLSQP")
stopSLSQP = timeit.default_timer()

print stopSLSQP - startSLSQP

print costFResultSLSQP


242.280678034
  status: 0
 success: True
    njev: 33
    nfev: 4035
     fun: 1.0950808681868152e-06
       x: array([  4.01819479e+00,   4.01819358e+00,   4.01819459e+00,
         4.01815238e+00,   4.01818511e+00,  -4.43244659e+00,
        -4.43244733e+00,  -4.43244623e+00,  -4.43244156e+00,
        -4.43244640e+00,  -1.35616173e+01,  -1.35616208e+01,
        -1.35616172e+01,  -1.35616071e+01,  -1.35616180e+01,
        -5.01926534e-01,  -5.01924586e-01,  -5.01924387e-01,
        -5.01925334e-01,  -5.01921256e-01,  -8.30089534e+00,
        -8.30089598e+00,  -8.30089534e+00,  -8.30089534e+00,
        -8.30089496e+00,  -2.32350862e+01,  -2.32350889e+01,
        -2.32350891e+01,  -2.32350876e+01,  -2.32350821e+01,
        -5.02070102e-01,  -5.02070102e-01,  -5.02070085e-01,
        -5.02121905e-01,  -5.02069726e-01,  -8.30085466e+00,
        -8.30085502e+00,  -8.30085502e+00,  -8.30083682e+00,
        -8.30085525e+00,  -2.32349391e+01,  -2.32349389e+01,
        -2.32349389e+01,  -2.32348930e+01,  -2.32349391e+01,
        -3.10549105e-04,  -3.11004187e-04,  -3.07807173e-04,
        -2.79353943e-04,  -2.62642230e-04,  -9.03448967e-01,
        -9.03448138e-01,  -9.03448125e-01,  -9.03429763e-01,
        -9.03423690e-01,  -2.39471084e+00,  -2.39471288e+00,
        -2.39470956e+00,  -2.39467803e+00,  -2.39466807e+00,
        -2.32304786e-06,  -1.32247631e-06,  -2.32304784e-06,
         1.11775437e-05,  -3.26027904e-06,   6.53019147e-01,
         6.53019029e-01,   6.53019147e-01,   6.53023331e-01,
         6.53019144e-01,   5.19826973e-01,   5.19827740e-01,
         5.19826973e-01,   5.19834672e-01,   5.19826569e-01,
         3.80921479e-01,   3.80921479e-01,   3.80921479e-01,
         3.80880677e-01,   3.80921309e-01,  -3.32170863e+00,
        -3.32170863e+00,  -3.32170863e+00,  -3.32168553e+00,
        -3.32170862e+00,  -8.16757401e+00,  -8.16757401e+00,
        -8.16757401e+00,  -8.16752198e+00,  -8.16757398e+00,
         3.80893479e-01,   3.80893480e-01,   3.80896031e-01,
         3.80864775e-01,   3.80896031e-01,  -3.32165007e+00,
        -3.32165007e+00,  -3.32165007e+00,  -3.32163484e+00,
        -3.32165007e+00,  -8.16744848e+00,  -8.16744848e+00,
        -8.16745186e+00,  -8.16742559e+00,  -8.16745186e+00,
        -2.41900762e-01,  -2.41900784e-01,  -2.41899944e-01,
        -2.41923051e-01,  -2.41900205e-01,  -2.47741186e+00,
        -2.47741186e+00,  -2.47741191e+00,  -2.47741015e+00,
        -2.47741182e+00,  -7.60498356e+00,  -7.60498346e+00,
        -7.60498416e+00,  -7.60497815e+00,  -7.60498398e+00])
 message: 'Optimization terminated successfully.'
     jac: array([  6.80131507e-11,   6.80131507e-11,   6.80131507e-11,
         6.80131507e-11,   6.80131507e-11,  -2.70006240e-13,
        -2.70006240e-13,  -2.70006240e-13,  -2.70006240e-13,
        -2.70006240e-13,   2.73388423e-10,   2.73388423e-10,
         2.73388423e-10,   2.73388423e-10,   2.73388423e-10,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
        -3.19045545e-05,  -3.19045009e-05,  -3.19045997e-05,
        -3.19056897e-05,  -3.19060365e-05,   2.58664556e-09,
         2.59043986e-09,   2.56382293e-09,   2.32691377e-09,
         2.18773266e-09,   9.23145649e-09,   9.24495680e-09,
         9.14995724e-09,   8.30441138e-09,   7.80769938e-09,
         5.77011733e-06,   5.77011853e-06,   5.77011733e-06,
         5.77013421e-06,   5.77011664e-06,  -2.07478479e-12,
        -1.17950094e-12,  -2.07478479e-12,   9.87654403e-12,
        -2.89901436e-12,  -3.93640676e-12,  -2.24531505e-12,
        -3.93640676e-12,   1.89430693e-11,  -5.52802248e-12,
         3.63076538e-07,   3.63076538e-07,   3.63076538e-07,
         3.63095879e-07,   3.63076552e-07,   7.46531725e-09,
         7.46531725e-09,   7.46531725e-09,   7.46494777e-09,
         7.46530304e-09,   1.38268717e-07,   1.38268717e-07,
         1.38268717e-07,   1.38261257e-07,   1.38268646e-07,
         3.63143954e-07,   3.63143954e-07,   3.63142718e-07,
         3.63152552e-07,   3.63142718e-07,   7.46651097e-09,
         7.46651097e-09,   7.46652518e-09,   7.46615569e-09,
         7.46652518e-09,   1.38284207e-07,   1.38284207e-07,
         1.38284676e-07,   1.38277073e-07,   1.38284676e-07,
        -6.27306775e-07,  -6.27306846e-07,  -6.27306406e-07,
        -6.27310214e-07,  -6.27306520e-07,   4.41717418e-09,
         4.41718839e-09,   4.41715997e-09,   4.41761472e-09,
         4.41715997e-09,   1.51674243e-07,   1.51674271e-07,
         1.51673632e-07,   1.51689022e-07,   1.51673831e-07,
         0.00000000e+00])
     nit: 33
 
*** Profile stats marshalled to file u'/var/folders/mj/1sl30v6x2g5_lnlgdnngtd3c0000gn/T/tmp5Pz1GB'. 

In [377]:
costFResultSLSQP.get('x')


Out[377]:
array([  4.01819479e+00,   4.01819358e+00,   4.01819459e+00,
         4.01815238e+00,   4.01818511e+00,  -4.43244659e+00,
        -4.43244733e+00,  -4.43244623e+00,  -4.43244156e+00,
        -4.43244640e+00,  -1.35616173e+01,  -1.35616208e+01,
        -1.35616172e+01,  -1.35616071e+01,  -1.35616180e+01,
        -5.01926534e-01,  -5.01924586e-01,  -5.01924387e-01,
        -5.01925334e-01,  -5.01921256e-01,  -8.30089534e+00,
        -8.30089598e+00,  -8.30089534e+00,  -8.30089534e+00,
        -8.30089496e+00,  -2.32350862e+01,  -2.32350889e+01,
        -2.32350891e+01,  -2.32350876e+01,  -2.32350821e+01,
        -5.02070102e-01,  -5.02070102e-01,  -5.02070085e-01,
        -5.02121905e-01,  -5.02069726e-01,  -8.30085466e+00,
        -8.30085502e+00,  -8.30085502e+00,  -8.30083682e+00,
        -8.30085525e+00,  -2.32349391e+01,  -2.32349389e+01,
        -2.32349389e+01,  -2.32348930e+01,  -2.32349391e+01,
        -3.10549105e-04,  -3.11004187e-04,  -3.07807173e-04,
        -2.79353943e-04,  -2.62642230e-04,  -9.03448967e-01,
        -9.03448138e-01,  -9.03448125e-01,  -9.03429763e-01,
        -9.03423690e-01,  -2.39471084e+00,  -2.39471288e+00,
        -2.39470956e+00,  -2.39467803e+00,  -2.39466807e+00,
        -2.32304786e-06,  -1.32247631e-06,  -2.32304784e-06,
         1.11775437e-05,  -3.26027904e-06,   6.53019147e-01,
         6.53019029e-01,   6.53019147e-01,   6.53023331e-01,
         6.53019144e-01,   5.19826973e-01,   5.19827740e-01,
         5.19826973e-01,   5.19834672e-01,   5.19826569e-01,
         3.80921479e-01,   3.80921479e-01,   3.80921479e-01,
         3.80880677e-01,   3.80921309e-01,  -3.32170863e+00,
        -3.32170863e+00,  -3.32170863e+00,  -3.32168553e+00,
        -3.32170862e+00,  -8.16757401e+00,  -8.16757401e+00,
        -8.16757401e+00,  -8.16752198e+00,  -8.16757398e+00,
         3.80893479e-01,   3.80893480e-01,   3.80896031e-01,
         3.80864775e-01,   3.80896031e-01,  -3.32165007e+00,
        -3.32165007e+00,  -3.32165007e+00,  -3.32163484e+00,
        -3.32165007e+00,  -8.16744848e+00,  -8.16744848e+00,
        -8.16745186e+00,  -8.16742559e+00,  -8.16745186e+00,
        -2.41900762e-01,  -2.41900784e-01,  -2.41899944e-01,
        -2.41923051e-01,  -2.41900205e-01,  -2.47741186e+00,
        -2.47741186e+00,  -2.47741191e+00,  -2.47741015e+00,
        -2.47741182e+00,  -7.60498356e+00,  -7.60498346e+00,
        -7.60498416e+00,  -7.60497815e+00,  -7.60498398e+00])

In [378]:
np.savetxt('./assets/homogen/optimize_ResultSLSQPT2120.txt', costFResultSLSQP.get('x'), delimiter = ',')

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:

Functions

Find the solutions to each elements.


In [359]:
# costFResultSLSQPx = np.genfromtxt('./assets/homogen/optimize_ResultSLSQP.txt', delimiter = ',')

In [379]:
## The first element of neutrino density matrix
xresult = np.split(costFResultSLSQP.get('x'),2)[0]
xresultb = np.split(costFResultSLSQP.get('x'),2)[1]
#xresult = np.split(costFResultSLSQPx,2)[0]
#xresultb = np.split(costFResultSLSQPx,2)[1]
## print xresult11

plttlin=np.linspace(0,5,100)

pltdata11 = np.array([])
pltdata22 = np.array([])

for i in plttlin:
    pltdata11 = np.append(pltdata11 ,rho(xresult,i,init)[0,0] )
    
print pltdata11

for i in plttlin:
    pltdata22 = np.append(pltdata22 ,rho(xresult,i,init)[1,1] )
    
print pltdata22

print "----------------------------------------"

pltdatab11 = np.array([])
pltdatab22 = np.array([])

for i in plttlin:
    pltdatab11 = np.append(pltdatab11 ,rho(xresultb,i,init)[0,0] )
    
print pltdatab11

for i in plttlin:
    pltdatab22 = np.append(pltdatab22 ,rho(xresultb,i,init)[1,1] )
    
print pltdatab22


[ 1.          1.00000105  1.00000167  1.000002    1.00000214  1.00000214
  1.00000205  1.00000191  1.00000175  1.00000157  1.00000139  1.00000123
  1.00000107  1.00000093  1.0000008   1.00000068  1.00000058  1.00000049
  1.00000042  1.00000035  1.0000003   1.00000025  1.00000021  1.00000017
  1.00000015  1.00000012  1.0000001   1.00000008  1.00000007  1.00000006
  1.00000005  1.00000004  1.00000003  1.00000003  1.00000002  1.00000002
  1.00000001  1.00000001  1.00000001  1.00000001  1.00000001  1.00000001
  1.          1.          1.          1.          1.          1.          1.
  1.          1.          1.          1.          1.          1.          1.
  1.          1.          1.          1.          1.          1.          1.
  1.          1.          1.          1.          1.          1.          1.
  1.          1.          1.          1.          1.          1.          1.
  1.          1.          1.          1.          1.          1.          1.
  1.          1.          1.          1.          1.          1.          1.
  1.          1.          1.          1.          1.          1.          1.
  1.          1.        ]
[  0.00000000e+00  -5.95594136e-06  -1.14214073e-05  -1.64242648e-05
  -2.09912366e-05  -2.51479179e-05  -2.89187966e-05  -3.23272748e-05
  -3.53956936e-05  -3.81453582e-05  -4.05965664e-05  -4.27686360e-05
  -4.46799351e-05  -4.63479121e-05  -4.77891261e-05  -4.90192782e-05
  -5.00532424e-05  -5.09050970e-05  -5.15881551e-05  -5.21149955e-05
  -5.24974930e-05  -5.27468483e-05  -5.28736168e-05  -5.28877379e-05
  -5.27985625e-05  -5.26148804e-05  -5.23449467e-05  -5.19965080e-05
  -5.15768265e-05  -5.10927048e-05  -5.05505087e-05  -4.99561899e-05
  -4.93153075e-05  -4.86330487e-05  -4.79142486e-05  -4.71634096e-05
  -4.63847195e-05  -4.55820689e-05  -4.47590684e-05  -4.39190639e-05
  -4.30651523e-05  -4.22001962e-05  -4.13268371e-05  -4.04475092e-05
  -3.95644516e-05  -3.86797203e-05  -3.77951993e-05  -3.69126118e-05
  -3.60335298e-05  -3.51593841e-05  -3.42914733e-05  -3.34309724e-05
  -3.25789409e-05  -3.17363307e-05  -3.09039933e-05  -3.00826864e-05
  -2.92730809e-05  -2.84757665e-05  -2.76912579e-05  -2.69199999e-05
  -2.61623725e-05  -2.54186960e-05  -2.46892351e-05  -2.39742036e-05
  -2.32737680e-05  -2.25880514e-05  -2.19171369e-05  -2.12610710e-05
  -2.06198667e-05  -1.99935062e-05  -1.93819437e-05  -1.87851081e-05
  -1.82029048e-05  -1.76352186e-05  -1.70819153e-05  -1.65428436e-05
  -1.60178371e-05  -1.55067157e-05  -1.50092877e-05  -1.45253502e-05
  -1.40546915e-05  -1.35970917e-05  -1.31523240e-05  -1.27201557e-05
  -1.23003495e-05  -1.18926638e-05  -1.14968541e-05  -1.11126734e-05
  -1.07398730e-05  -1.03782033e-05  -1.00274141e-05  -9.68725557e-06
  -9.35747814e-06  -9.03783348e-06  -8.72807465e-06  -8.42795653e-06
  -8.13723614e-06  -7.85567296e-06  -7.58302917e-06  -7.31906990e-06]
----------------------------------------
[ 1.          1.00000006  1.00000013  1.00000019  1.00000026  1.00000033
  1.0000004   1.00000047  1.00000054  1.00000061  1.00000069  1.00000077
  1.00000084  1.00000092  1.000001    1.00000108  1.00000117  1.00000125
  1.00000133  1.00000142  1.00000151  1.00000159  1.00000168  1.00000177
  1.00000186  1.00000195  1.00000204  1.00000214  1.00000223  1.00000232
  1.00000242  1.00000251  1.00000261  1.00000271  1.0000028   1.0000029
  1.000003    1.0000031   1.0000032   1.0000033   1.0000034   1.0000035
  1.0000036   1.0000037   1.0000038   1.0000039   1.000004    1.00000411
  1.00000421  1.00000431  1.00000442  1.00000452  1.00000462  1.00000473
  1.00000483  1.00000493  1.00000504  1.00000514  1.00000525  1.00000535
  1.00000546  1.00000556  1.00000567  1.00000577  1.00000588  1.00000598
  1.00000609  1.00000619  1.0000063   1.0000064   1.0000065   1.00000661
  1.00000671  1.00000682  1.00000692  1.00000703  1.00000713  1.00000724
  1.00000734  1.00000745  1.00000755  1.00000766  1.00000776  1.00000787
  1.00000797  1.00000807  1.00000818  1.00000828  1.00000839  1.00000849
  1.0000086   1.0000087   1.0000088   1.00000891  1.00000901  1.00000911
  1.00000922  1.00000932  1.00000942  1.00000953]
[  0.00000000e+00  -2.68297775e-05  -4.73510700e-05  -6.26759821e-05
  -7.37424647e-05  -8.13398510e-05  -8.61308070e-05  -8.86701830e-05
  -8.94211887e-05  -8.87692607e-05  -8.70339383e-05  -8.44790252e-05
  -8.13212736e-05  -7.77377989e-05  -7.38724016e-05  -6.98409518e-05
  -6.57359678e-05  -6.16305056e-05  -5.75814558e-05  -5.36323352e-05
  -4.98156449e-05  -4.61548596e-05  -4.26661007e-05  -3.93595411e-05
  -3.62405815e-05  -3.33108322e-05  -3.05689296e-05  -2.80112136e-05
  -2.56322869e-05  -2.34254738e-05  -2.13831957e-05  -1.94972761e-05
  -1.77591856e-05  -1.61602386e-05  -1.46917473e-05  -1.33451431e-05
  -1.21120681e-05  -1.09844446e-05  -9.95452452e-06  -9.01492350e-06
  -8.15864279e-06  -7.37908053e-06  -6.67003525e-06  -6.02570301e-06
  -5.44066964e-06  -4.90989938e-06  -4.42872075e-06  -3.99281050e-06
  -3.59817635e-06  -3.24113892e-06  -2.91831334e-06  -2.62659091e-06
  -2.36312091e-06  -2.12529295e-06  -1.91071987e-06  -1.71722133e-06
  -1.54280819e-06  -1.38566766e-06  -1.24414940e-06  -1.11675233e-06
  -1.00211235e-06  -8.98990930e-07  -8.06264378e-07  -7.22914005e-07
  -6.48016953e-07  -5.80737746e-07  -5.20320499e-07  -4.66081758e-07
  -4.17403913e-07  -3.73729169e-07  -3.34554013e-07  -2.99424169e-07
  -2.67929972e-07  -2.39702167e-07  -2.14408066e-07  -1.91748052e-07
  -1.71452407e-07  -1.53278421e-07  -1.37007768e-07  -1.22444132e-07
  -1.09411046e-07  -9.77499396e-08  -8.73183715e-08  -7.79884275e-08
  -6.96452743e-08  -6.21858520e-08  -5.55176930e-08  -4.95578558e-08
  -4.42319640e-08  -3.94733380e-08  -3.52222141e-08  -3.14250394e-08
  -2.80338381e-08  -2.50056402e-08  -2.23019675e-08  -1.98883716e-08
  -1.77340182e-08  -1.58113134e-08  -1.40955681e-08  -1.25646963e-08]

In [380]:
#np.savetxt('./assets/homogen/optimize_pltdatar11.txt', pltdata11, delimiter = ',')
#np.savetxt('./assets/homogen/optimize_pltdatar22.txt', pltdata22, delimiter = ',')

In [381]:
plt.figure(figsize=(20,12.36))
plt.ylabel('Time')
plt.xlabel('rho11')
plt.plot(plttlin,pltdata11,"b4-",label="rho11")
py.iplot_mpl(plt.gcf(),filename="HG-rho11")


# tls.embed("https://plot.ly/~emptymalei/73/")


Out[381]:

In [382]:
plt.figure(figsize=(20,12.36))
plt.ylabel('Time')
plt.xlabel('rho22')
plt.plot(plttlin,pltdata22,"r4-",label="rho22")
py.iplot_mpl(plt.gcf(),filename="HG-rho22")


Out[382]:

In [383]:
plt.figure(figsize=(20,12.36))
plt.ylabel('Time')
plt.xlabel('rhob11')
plt.plot(plttlin,pltdatab11,"b*-",label="rhob11")
py.iplot_mpl(plt.gcf(),filename="HG-rhob11")


Out[383]:

In [384]:
plt.figure(figsize=(20,12.36))
plt.ylabel('Time')
plt.xlabel('rhob22')
plt.plot(plttlin,pltdatab11,"b*-",label="rhob22")
py.iplot_mpl(plt.gcf(),filename="HG-rhob22")


Out[384]:

In [385]:
MMA_optmize_pltdata = np.genfromtxt('./assets/homogen/MMA_optmize_pltdata.txt', delimiter = ',')

plt.figure(figsize=(20,12.36))
plt.ylabel('MMArho11')
plt.xlabel('Time')
plt.plot(np.linspace(0,5,501),MMA_optmize_pltdata,"r-",label="MMArho11")
plt.plot(plttlin,pltdata11,"b4-",label="rho11")
py.iplot_mpl(plt.gcf(),filename="MMA-rho11")


Out[385]:

In [ ]:


In [ ]:

Practice


In [367]:
xtemp1 = np.arange(4)
xtemp1.shape = (2,2)
print xtemp1
xtemp1[0,1]
np.dot(xtemp1,xtemp1)
xtemp1[0,1]


[[0 1]
 [2 3]]
Out[367]:
1

In [ ]: