Scilab Programs
Scilab Programs
Linear algebra:
1 Multiplication of two 3 x 3 matrices.
INPUT:
clc;
a=[1 2 3;4 5 6;1 4 3]
b=[2 1 1;1 3 2;3 1 4]
disp(a,"matrix a")
disp(b,"matrix b")
disp(a*b,"Product of a and b")
OUTPUT:
matrix a matrix c
1 2 3 6 8.i 7
4 5 6 3 1 2.i
1 4 3 8 i 5
matrix b matriix d
2 1 1 2 -5 3.i
1 3 2 i 2 3
3 1 4 -2.i 3 -5
2 1 1 1 -i 3+4i
1 3 2 i 2 4
3 1 4 3-4i 4 3
INPUT:
INPUT:
clc;
clc;
a=[1 -%i 3+4*(%i) ;%i 2 4;3-4*%i 4 3]
a=[2 1 1;1 3 2;3 1 4]
disp(a,"matrix a")
disp(a,"matrix a")
[r,e]=spec(a)
[r,e]=spec(a)
disp(r, "Eigenvectors")
disp([r,e],"Eigenvectors and
disp(e,"Eigenvalues")
Eigenvalues")
OUTPUT:
OUTPUT:
matrix a
matrix a
1 -i 3 + 4.i
2 1 1
i 2 4
1 3 2
3 – 4.i 4 3
3 1 4
Eigenvalues
6.095824 0. 0. -4.746829 0 0
0 1.4521 + 0.433i 0. 0 2.3968018 0
0 0 1.4521 - 0.433 0 0 8.3500273
2 -i 2i
i 4 3
-2i 3 5
INPUT:
clc;
a=[2 -%i 2*(%i) ;%i 4 3;-2*%i 3 5]
disp(a,"matrix a")
[r,e]=spec(a)
disp(r, "Eigenvectors")
disp(e,"Eigenvalues")
OUTPUT:
matrix a
2 -i 2.i
i 4 3
-2.i 3 5
Eigenvectors
Eigenvalues
-0.3871996 0. 0.
0. 3.6916109 0.
0. 0. 7.6955887
2. Orthogonal polynomials as eigenfunctions of Hermitian differential operators.
Hermite Polynomials:
/
(−1) 𝑛! (2𝑥)
H (x) =
𝑘! (𝑛 − 2𝑘)!
Orthogonality relation:
0, n≠m
e H (x)H (x)dx =
√π2 n!, n=m
INPUT:
clc;
funcprot(0)
function y=H(n, x)
y=0
for i=0:floor(n/2)
y =y+((factorial(n)*((-1)^i)*(2*x)^(n-2*i))/(factorial(i)*factorial(n-2*i)))
end
endfunction
n=input("Order of Hermite Polynomial(n): ")
x=poly(0,"x");
disp(H(n,x),"Hermite Polynomial H(n,x)")
s=-2:0.0001:2
plot2d(s,H(n,s),5)
disp("Theoritical value")
if n==m then
disp(factorial(n)*(2^n)*sqrt(%pi))
else
disp(0)
end
OUTPUT:
Theoritical value
85.077785
3. Determination of the principal axes of moment of inertia through diagonalization
( ) ( ) ( )
I𝒋𝒑 = m [δ (r ) −r r ]
INPUT:
clc;
clf();
n=input("no. of particles: ")
MI1=zeros(3,3);
MI2=zeros(3,3);
krocdelta=eye(3,3);
for i=1:n
m(i)=input("mass of particle " +string(i)+ " : ")
end
disp(m)
for i=1:n
for j=1:3
r(i,j)=input("coordinate " +string(j)+ " of particle "+string(i)+ " : ")
end
end
disp(r)
for j=1:3
for k=1:3
for i=1:n
MI1(j,k)=MI1(j,k)+m(i)*r(i,j)*r(i,k);
end
end
end
sqr=r'*r;
for j=1:3
for k=1:3
for i=1:n
MI2(j,k)=MI2(j,k)+m(i)*krocdelta(j,k)*sqr(k,k);
no. of particles: 2
mass of particle 1 : 67
mass of particle 2 : 89
67. Moment of Inertia tensor
89.
541476. -36582. -10452.
coordinate 1 of particle 1 : 78 -36582. 4428. -1205.
coordinate 2 of particle 1 : 7 -10452. -1205. 959.
coordinate 3 of particle 1 : 2
coordinate 1 of particle 2 : 0 Principal axis
coordinate 2 of particle 2 : 1
coordinate 3 of particle 2 : 3 -0.0553779 -0.0431459 -0.9975328
-0.5906563 -0.8040893 0.0675692
78. 7. 2. -0.8050208 0.5929409 0.0190444
0. 1. 3.
x=x
Commutator:
∂ [𝑎 , 𝑏]= 𝑎𝑏-𝑏𝑎
p = −iℏ
∂x
( )
[𝑥 ,𝑝̂ ]𝜓= x −iℏ − −iℏ =𝑖ℏ𝜓
Let us see the action of the commutator on legendre and hermite polynomials as
wavefunctions
1 d
Legendre Polynomial: P (x) = (x − 1) (Rodrigue s formula)
2 n! dx
/
(−1) 𝑛! (2𝑥)
Hermite Polynomial: H (x) =
𝑘! (𝑛 − 2𝑘)!
INPUT:
clc; disp(legendrepoly,"Legendre
x=poly(0,"x"); Polynomial");
p=(x^(2)-1);
n=input("order of polynomial: "); ///commutator
printf("the action of commutator on
///making legendre polynomial(Rodrigue's legendre polynomial of order %i",n);
formula)
for k=0:n z=-%i*x*derivat(legendrepoly); ///let
p=(x^(2)-1)^(k); hbar=1
end
if (n==0) then w=x*legendrepoly;
legendrepoly=p t=-%i*derivat(w);
else commutator=z-t;
y=derivat(p) disp(commutator)
for j=1:n-1
y=derivat(y)
end
legendrepoly=(y)/(factorial(n)*2^n)
end
OUTPUT:
order of polynomial: 4
Legendre Polynomial
0.375 -3.75𝑥 +4.375𝑥
Real part
0
Imaginary part
0.375 -3.75𝑥 +4.375𝑥
INPUT:
clc; printf("the action of commutator on
funcprot(0) Hermite polynomial of order %i",n);
function y=H(n, x)
y=0 z=-%i*x*derivat(H(n,x)); //hbar=1
for i=0:floor(n/2) w=x*H(n,x);
y =y+((factorial(n)*((- t=-%i*derivat(w);
1)^i)*(2*x)^(n- commutator=z-t;
2*i))/(factorial(i)*factorial(n-2*i))) disp(commutator)
end
endfunction
n=input("Order of Hermite
Polynomial(n): ")
x=poly(0,"x");
disp(H(n,x),"Hermite Polynomial H(n,x)")
OUTPUT:
Order of Hermite Polynomial(n): 3
Real part
0
Imaginary part
-12x +8𝑥
2 𝑛𝜋𝑥
𝑊𝑎𝑣𝑒𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛: 𝜓 (𝑥) = sin
𝑎 𝑎
𝑛 𝜋 ℏ
𝐸𝑛𝑒𝑟𝑔𝑦: 𝐸 =
2𝑚𝑎
INPUT:
clc; n=input("State(n),whose eigenvalue you
funcprot(0); seek: ")
hbar=6.626*10^(-34)/(2*%pi)
if d<20 then
a=input("Length of the box: ") disp("Answer would not be accurate,
m=input("Mass of the particle(in Kg): ") re-enter: ")
d=input("No. of divisions: ") d=input("No. of divisions: ")
end if j<d-1
k=hbar**2/m H(j,j+1)=-k
function potential=V(x) H(j+1,j)=-k
potential=0 end
endfunction end
RH=H/(2*(h**2))
xmax=a [ef,ev]=spec(RH)
xmin=0
h=(xmax-xmin)/d s=linspace(h,a,d-1)
plot2d(s,ef(:,n))
r=0 ///r≡x disp(nansum(ev(:,n)),"Eigenvalue of the
H=zeros(d-1,d-1) ///psi is zero at x=0 asked state")
and x=a(or dh)
for j=1:d-1 En=(n^2*(%pi)^2*hbar^2)/(2*m*(a^2))
r=r+h disp(En,"Theoritical value for the
H(j,j)=2*(k-V(r)*(h**2)) eigenvalue(i.e,energy)")
OUTPUT:
Graph of 𝝍𝟏 (𝒙) →