Done - Eigen Values - Eigen Vectors - Diagonalize a Matrix

ToBeDone - Integrate an Integral - Express a pontential \(P\) as in the basis of wavefunctions from another

In [23]:
using PyPlot
whos()
Warning: Possible conflict in library symbol dtrtri_
Warning: Possible conflict in library symbol dgetri_
Warning: Possible conflict in library symbol dgetrf_

Base                          Module
BinDeps                       Module
Color                         Module
Core                          Module
Homebrew                      Module
IJulia                        Module
IPythonDisplay                Module
JSON                          Module
Main                          Module
Nettle                        Module
PyCall                        Module
PyPlot                        Module
REPLCompletions               Module
URIParser                     Module
ZMQ                           Module
_10                           Function
_12                           5x5 Array{Float64,2}
_13                           Float64
_14                           Function
_15                           6x6 Array{Float64,2}
_16                           Function
_17                           7x7 Array{Float64,2}
_18                           6x6 Array{Float64,2}
_19                           6x6 Array{Float64,2}
_2                            5x5 Array{Float64,2}
_20                           6-element Array{Int64,1}
_21                           6-element Array{Float64,1}
_6                            5x5 Array{Float64,2}
_7                            5x5 Array{Float64,2}
_9                            Int64
a                             6x6 Array{Float64,2}
b                             6x6 Array{Float64,2}
identity                      Function
identitymat                   Function
v                             6-element Array{Int64,1}

In []:
In [9]:
max(2,4)
Out[9]:
4
In [7]:
a = zeros(5,5)
Out[7]:
5x5 Array{Float64,2}:
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
In [16]:
function identitymat(n,m)
    mat = zeros(n,m)
    for i = [1:min(n,m)]
        mat[i,i] = 1.0
    end
    return mat
end

function identity(n)
    return identitymat(n,n)
end
Out[16]:
identity (generic function with 1 method)
In [19]:
a = identitymat(6,6)
b = identity(6)
a*b
Out[19]:
6x6 Array{Float64,2}:
 1.0  0.0  0.0  0.0  0.0  0.0
 0.0  1.0  0.0  0.0  0.0  0.0
 0.0  0.0  1.0  0.0  0.0  0.0
 0.0  0.0  0.0  1.0  0.0  0.0
 0.0  0.0  0.0  0.0  1.0  0.0
 0.0  0.0  0.0  0.0  0.0  1.0
In [20]:
v = [1:6]
Out[20]:
6-element Array{Int64,1}:
 1
 2
 3
 4
 5
 6
In [21]:
a*v
Out[21]:
6-element Array{Float64,1}:
 1.0
 2.0
 3.0
 4.0
 5.0
 6.0
In [29]:
c = round(rand(5,5)*10)
Out[29]:
5x5 Array{Float64,2}:
 2.0  3.0   4.0  9.0  5.0
 6.0  7.0   8.0  3.0  2.0
 9.0  3.0   1.0  5.0  5.0
 4.0  4.0  10.0  2.0  4.0
 9.0  5.0   8.0  3.0  4.0
In [31]:
c * [1:5]
Out[31]:
5-element Array{Float64,1}:
 81.0
 66.0
 63.0
 70.0
 75.0
In [33]:
ec = eigvecs(c)
Out[33]:
5x5 Array{Complex{Float64},2}:
 -0.415734+0.0im          0.617491+0.0im  …   0.309403+0.0im   0.217338+0.0im
 -0.458323+0.0im    -0.198186+0.112127im      -0.42197+0.0im  -0.923562+0.0im
 -0.414135+0.0im   -0.0475526-0.433644im      0.240968+0.0im   0.257813+0.0im
 -0.426812+0.0im    -0.189487+0.430945im      0.345162+0.0im    0.16022+0.0im
 -0.513254+0.0im  -0.393599+0.00279561im     -0.740951+0.0im   0.087522+0.0im
In [38]:
vc = eigvals(c)
Out[38]:
5-element Array{Complex{Float64},1}:
     24.7046+0.0im
 -5.21978+4.0394im
 -5.21978-4.0394im
   -0.909916+0.0im
     2.64487+0.0im
In [39]:
vc[1] * ec[:,1]
Out[39]:
5-element Array{Complex{Float64},1}:
 -10.2705+0.0im
 -11.3227+0.0im
  -10.231+0.0im
 -10.5442+0.0im
 -12.6797+0.0im
In [40]:
c * ec[:,1]
Out[40]:
5-element Array{Complex{Float64},1}:
 -10.2705+0.0im
 -11.3227+0.0im
  -10.231+0.0im
 -10.5442+0.0im
 -12.6797+0.0im
In [72]:
function withintolerance(u,v, tol)
    pass = true
    if (length(u) != length(v))
        println(" OOPS - u and v are not of the same length!")
        return 1
    end
    for i = [1:length(u)]
        if ( real(v[i] - u[i]) > tol ) 
            pass = false
        end
    end
    return pass
end
Out[72]:
withintolerance (generic function with 1 method)
In [81]:
c1 = vc[1] * ec[:,1]
c2 = c * ec[:,1]
withintolerance(c1, c2, 1e-13)
Out[81]:
true
In [75]:
1e-4 / 10.0
Out[75]:
1.0e-5
In [71]:
real(1+0im - 2+0im)
Out[71]:
-1
In [84]:
function perr(o,a)
    return abs(o-a)*100/a
end
Out[84]:
perr (generic function with 1 method)
In [85]:
c
Out[85]:
5x5 Array{Float64,2}:
 2.0  3.0   4.0  9.0  5.0
 6.0  7.0   8.0  3.0  2.0
 9.0  3.0   1.0  5.0  5.0
 4.0  4.0  10.0  2.0  4.0
 9.0  5.0   8.0  3.0  4.0
In [86]:
diag(c)
Out[86]:
5-element Array{Float64,1}:
 2.0
 7.0
 1.0
 2.0
 4.0
In [89]:
inv(c)
Out[89]:
5x5 Array{Float64,2}:
  0.0185328  -0.116602   -0.112741  -0.218533    0.394595
 -0.152124    0.415444    0.342085   0.252124   -0.697297
  0.0810811  -0.135135   -0.243243  -0.0810811   0.351351
  0.221622   -0.102703   -0.264865  -0.321622    0.427027
 -0.179923    0.0903475   0.511197   0.579923   -0.789189
In [92]:
dc = diag(inv(ec)*c*ec)
Out[92]:
5-element Array{Complex{Float64},1}:
    24.7046-2.2803e-31im
       -5.21978+4.0394im
       -5.21978-4.0394im
 -0.909916-2.15775e-17im
    2.64487+1.4957e-17im
In [93]:
quadgk
Out[93]:
quadgk (generic function with 3 methods)
In [94]:
quadgk(sin,0,2pi)
Out[94]:
(-6.61545509678121e-16,7.651420666115506e-24)
Warning: Possible conflict in library symbol dstev_

In [104]:
quadgk(x->cos(x),0,2pi)
Out[104]:
(3.087018938780625e-14,1.2378408900035138e-20)
In [105]:
#compose two functions
function myCompose(f,g)
    #given two functions of 1 variable each
    return (x,y)->(f(x)*g(y))
end
foo = myCompose(x->x, x->x)
println(foo(2,2))
println(foo(2,4))
function compose(f,g)
    return (x)->(f(x)*g(x))
end
println(quadgk(sin,0,pi))
println(quadgk(compose(sin,cos),0,pi))
[sin, cos]
4
8
(
Out[105]:
2-element Array{Function,1}:
 sin
 cos
In [106]:
Array(Function, 10)
Out[106]:
10-element Array{Function,1}:
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
In []:
#return the nth wavefunction of QHO
function wavefuncQHO(n)
        mw
        
        Cn = 1/(2^n * factorial(n)) 
        return x->(Cn*mw*)