1
Physics Practical DSE-1 :
Advanced Mathematical Physics-1 Lab
Name- Aakash YadavCourse- B.sc. (H) Physics
V SemesterExam Roll no.- 17035567002
College Roll no.- 6317
EXPERIMENT 1(a)
2
AIM- Write a scilab code for the multiplication of two 3x3 matrices
A=[2 5 11 7 39 6 4] B=[0 3 1
1 5 73 6 1]
EDITOR-clc()
//Defining the MatricesA=[2 5 1;1 7 3;9 6 4]B=[0 3 1;1 5 7;3 6 1]mprintf("The given matrices are-\nA=\n")mprintf("%d %d %d\n",A)
3
mprintf("\nB=\n")mprintf("%d %d %d\n",B)
[m,n]=size(A)[k,p]=size(B)C=zeros(3,3)
//Checking dimensions of matrix for multiplicationif n~=k then disp ('Dimensions of given matrix are not compatible')else // Multiplying matrices by LOOPfor i=1:m for j=1:p //s= 0; for r=1:n C(i,j) = C(i,j) + A(i,r) * B(r,j); end //C(i,j) = s endendendmprintf('\nThe multipication of matrices by loop multiplication is\n')mprintf('%4.0f %4.0f %4.0f\n',C)
//Multiplying Matrices directlyC=A*Bmprintf('\nThe multipication of matrices by direct multiplication is\n')
mprintf('%4.0f %4.0f %4.0f\n',C)
4
CONSOLE-The given matrices are-A=2 5 11 7 39 6 4
B=0 3 11 5 73 6 1
The multipication of matrices by loop multiplication is 8 37 38 16 56 53
5
18 81 55
The multipication of matrices by direct multiplication is 8 37 38 16 56 53 18 81 55
6
EXPERIMENT 1(b)
AIM- Write a scilab code for the multiplication of two 3x3 matrices
A=[1 6 94 7 2i8 i 0 ] B=[1+2i 3 4 i
0 8i 68 2i 1+i ]
EDITOR-clc()
//Defining the MatricesA=[1 6 9;4 7 2*%i;8 %i 0]B=[1+2*%i 3 4*%i;0 8*%i 6;8 2*%i 1+%i]
7
mprintf("The given matrices are-\nA=\n")disp(A)mprintf("\nB=\n")disp(B)
[m,n]=size(A)[k,p]=size(B)
//Checking dimensions of matrix for multiplicationif n~=k disp ('Dimensions of given matrix are not compatible')end // Multiplying matrices by for LOOPfor i=1:m for j=1:p s= 0; for r=1:n s = s + A(i,r) * B(r,j); end C(i,j) = s endend
//Multiplying Matrices directlymprintf('The multipication of matrices is\n')disp(C)
C=A*Bmprintf('\nThe multipication of matrices by direct multiplication is\n')disp(C)
8
CONSOLE-The given matrices are-
A=
1. 6. 9.
4. 7. 2.i
8. i 0
B=
1. + 2.i 3. 4.i
0 8.i 6.
8. 2.i 1. + i
The multipication of matrices is
73. + 2.i 3. + 66.i 45. + 13.i
9
4. + 24.i 8. + 56.i 40. + 18.i
8. + 16.i 16. 38.i
The multipication of matrices by direct multiplication is
73. + 2.i 3. + 66.i 45. + 13.i
4. + 24.i 8. + 56.i 40. + 18.i
8. + 16.i 16. 38.i
10
EXPERIMENT 2
AIM- To find transpose of the given matrix and to verify if it is orthogonal i.e. AA’=I
A= 13 *[2 −2 11 2 22 1 −2]
EDITOR-clc()
//Defining the MatrixA=[2 -2 1;1 2 2;2 1 -2]
11
A=A/3mprintf('The given matrix is A=\n')mprintf('%1.3f %1.3f %1.3f\n',A)B=zeros(3,3)
//Calculculating Transpose of matrix by for loopfor i=1:3 for j=1:3 B(i,j)=A(j,i) endend
mprintf('\nThe transpose of matrix by loop is A_trans=\n')mprintf('%1.3f %1.3f %1.3f\n',B)
//Calculculating Transpose of matrix directlymprintf('\nThe transpose of matrix calculated directly is A_trans=\n')mprintf('%1.3f %1.3f %1.3f\n',A')
mprintf("\nA x A_trans= =\n")mprintf('%1.3f %1.3f %1.3f\n',A*B)
//Verifying Orthogonality of Matrixif A*B==eye(3,3) thenmprintf('\n Hence Given matrix is an orthogonal matrix')end
12
CONSOLE-The given matrix is A=0.667 -0.667 0.3330.333 0.667 0.6670.667 0.333 -0.667
The transpose of matrix by loop is A_trans=0.667 0.333 0.667-0.667 0.667 0.3330.333 0.667 -0.667
The transpose of matrix calculated directly is A_trans=0.667 0.333 0.667
13
-0.667 0.667 0.3330.333 0.667 -0.667
A x A_trans= =1.000 0.000 0.0000.000 1.000 0.0000.000 0.000 1.000
Hence Given matrix is an orthogonal matrix
14
EXPERIMENT 3
AIM- To verify that the given matrix is a unitary matrix i.e. BB+=I
B= 1√3 *[ 1 1+i1−i −1 ]
EDITOR- clc()B=(1/sqrt(3))*([1 1+%i;1-%i -1])mprintf('\nyour matrix B is\n')
15
disp(B)C=B'mprintf('\nyour matrix C=conjugate-transpose of B is\n')disp(C)D=C*Bmprintf('\nthe marix D=C*B')disp(D)mprintf('\nthe given matrix is the the unitary matrix')
CONSOLE-your matrix B is 0.5773503 0.5773503 + 0.5773503i 0.5773503 - 0.5773503i - 0.5773503
your matrix C=conjugate-transpose of B is
16
0.5773503 0.5773503 + 0.5773503i 0.5773503 - 0.5773503i - 0.5773503
the marix D=C*B 1. 0 0 1.
the given matrix is the the unitary matrix
17
EXPERIMENT 4
AIM- To verify CC-1=I for any randomly chosen matrix C if |C|≠0
C=[1 3 44 2 51 4 6 ]
EDITOR-clc()a=[1 3 4;4 2 5;1 4 6]mprintf("mattrix a is")disp(a)
18
d=det(a)mprintf("Determinant of A\n|A|= ")mprintf("%d \n not equal to 0",d)if d==0 then mprintf("the inverse of given matrix is not possible")else b=inv(a) mprintf('\n\nInverse of A=') disp(b) c=a*b disp('A*inv(A)=') mprintf('%4.0f %4.0f %4.0f\n',c) mprintf("Hence verified") end
19
CONSOLE-Matrix A is 1. 3. 4. 4. 2. 5. 1. 4. 6. Determinant of A|A|= -8 not equal to 0
Inverse of A= 0.8888889 0.2222222 - 0.7777778 2.1111111 - 0.2222222 - 1.2222222 - 1.5555556 0.1111111 1.1111111 A*inv(A)= 1 0 -0 0 1 0 0 0 1Hence verified
20
EXPERIMENT 5
AIM- Matrix A gives the percentage of N,P,K in 3 fertilizers. Matrix B is amount of each type of fertilizer spread on 3 different field. Use matrix operations to find the total amount of N,P,K in each field N P K
A=F110% 50% 5%F225% 5% 5%F30% 10% 20%
f1 f2 f3
B=F15 2 4F22 1 1F33 1 3
F-Fertilizer f-Field
EDITOR- clc()mprintf("Given Data :-\n\n")
21
//Matrix AA=[10 10 5;25 5 5;0 10 20]mprintf(" \t\tN\tP\tK\n")mprintf("Fertiliser1\t%d\t%d\t%d\n",A(1,:))mprintf("Fertiliser2\t%d\t%d\t%d\n",A(2,:))mprintf("Fertiliser3\t%d\t%d\t%d\n",A(3,:))
//Matrix BB=[5 2 4;2 1 1;3 1 3]mprintf("\n\n \t\tfield1\tfield2\tfield3\n")mprintf("Fertiliser1\t%d\t%d\t%d\n",B(1,:))mprintf("Fertiliser2\t%d\t%d\t%d\n",B(2,:))mprintf("Fertiliser3\t%d\t%d\t%d\n",B(3,:))//fieldA=A/100C=A'*B
//Total amount
mprintf("\n\nTOTAL AMOUNT OF N,P,K in respective fields:-")
mprintf("\n\n \tN\tP\tK\n")mprintf("field1\t%1.2f\t%1.2f\t%1.2f\n",C(1,:))mprintf("field2\t%1.2f\t%1.2f\t%1.2f\n",C(2,:))mprintf("field3\t%1.2f\t%1.2f\t%1.2f\n",C(3,:))
22
CONSOLE-Given Data :-
N P KFertiliser110 10 5Fertiliser225 5 5Fertiliser30 10 20
field1 field2 field3Fertiliser15 2 4Fertiliser22 1 1Fertiliser33 1 3
23
TOTAL AMOUNT OF N,P,K in respective fields:-
N P Kfield1 1.00 0.45 0.65field2 0.90 0.35 0.75field3 0.95 0.35 0.85
24
EXPERIMENT 6(a)
AIM- To determine whether the given matrices are commutative
A=[1 0 00 1 01 0 2 ] B=[ 2 4 0
3 1 0−1 −4 1]
EDITOR- clc
a = [1 0 0;0 1 0;1 0 2]b = [2 4 0;3 1 0;-1 -4 1]
25
mprintf("The given matrices are:-\n")disp(a,"A=")disp(b,"B=")c = a*bc1 = b*amprintf("\nNow we have\nA*B :- \n")disp(c)mprintf("\n")mprintf("B*A :- \n")disp(c1)if c == c1 then mprintf("\nHence,The two matrices are commutative in nature \n")
else mprintf("The two matrices are not commutative in nature \n")end
CONSOLE-The given matrices are:- A= 1. 0. 0. 0. 1. 0.
26
1. 0. 2. B= 2. 4. 0. 3. 1. 0. - 1. - 4. 1.
Now we haveA*B :- 2. 4. 0. 3. 1. 0. 0. - 4. 2.
B*A :- 2. 4. 0. 3. 1. 0. 0. - 4. 2.
Hence,The two matrices are commutative in nature
27
28
EXPERIMENT 6(b)
AIM- To determine whether the given matrices are commutative
A=[1 23 4] B=[5 6
7 8]
EDITOR- clca = [1 2; 3 4]b = [5 6; 7 8]
mprintf("The given matrices are:-\n")
29
disp(a,"A=")disp(b,"B=")c = a*bc1 = b*amprintf("\nNow we have\nA*B :- \n")disp(c)mprintf("\n")mprintf("B*A :- \n")disp(c1)if c == c1 then mprintf("\nHence,The two matrices are commutative in nature \n")
else mprintf("The two matrices are not commutative in nature \n")end
CONSOLE-The given matrices are:- A= 1. 2. 3. 4. B=
30
5. 6. 7. 8.
Now we haveA*B :- 19. 22. 43. 50.
B*A :- 23. 34. 31. 46. The two matrices are not commutative in nature
31
EXPERIMENT 6(c)
AIM- Write a scilab code to show that all the diagonal matrix commute to all other diagonal matrix. Use diag(rand(1,3)) to generate A and B and prove that AB=BA
32
EDITOR- a = diag(rand(1,3))//disp(a)mprintf(" Given Diagonal Matrix A :- \n")disp(a)b = diag(rand(1,3))mprintf(" \n\nGiven Diagonal Matrix B :- \n")disp(b)mprintf("\n")//disp(b)c = a*bc1 = b*a
mprintf("A*B :- \n")disp(c)
mprintf("B*A :- \n")disp(c1)
if c == c1 then mprintf("\n\nThe two diagonal matrices are commutative in nature \n")else mprintf("The two diagonal matrices are not commutative in nature")endCONSOLE-Given Diagonal Matrix A :-
33
0.7783129 0. 0. 0. 0.2119030 0. 0. 0. 0.1121355
Given Diagonal Matrix B :-
0.6856896 0. 0. 0. 0.1531217 0. 0. 0. 0.6970851
A*B :-
0.5336810 0. 0. 0. 0.0324469 0. 0. 0. 0.0781680
B*A :-
0.5336810 0. 0. 0. 0.0324469 0. 0. 0. 0.0781680
34
The two diagonal matrices are commutative in nature
35
EXPERIMENT 7
AIM- Write a scilab code to show that if two symmetric matrices are commutative then their product is also symmetrici.e. if AB=BA then (AB)’=AB
EDITOR- clcA=[1 2;2 3]B=[4 5;5 6]disp(A,"Given matrix A")
36
disp(B,"Given matrix B")P=(A*B)'Q=B*AC=P-Q
if C==0 then mprintf('\nAB=BA\ngiven symmtric matrix is commutative\n')else mprintf('given matrix is not commutative\n')end
mprintf('\nA*B=')disp(P)mprintf('\ntranspose(AB)=')disp(Q)
W=A*Bif P == Q then mprintf('\nproduct of matrix is symmertic\n')else mprintf('prod is not symm.')end
37
CONSOLE-Given matrix A 1. 2. 2. 3. Given matrix B 4. 5. 5. 6.
AB=BAgiven symmtric matrix is commutative
38
A*B= 14. 23. 17. 28.
transpose(AB)= 14. 23. 17. 28.
product of matrix is symmetric
39
EXPERIMENT 8(a)
AIM- Write a scilab code to determine whether the given matrices are diagonalizable or not, and if diagonalizable then show thatP-1AP=D
A=[1 1 01 1 00 0 2 ]
EDITOR- clcA=[1 1 0;1 1 0;0 0 2][P,D]=spec(A)
40
mprintf('Coloumn of P are eigen vector of matrix A \n')mprintf(' and \n P=\n')
disp(P) //pmprintf('\ndigonlisable matrix D is\n D=')disp(D)d=det(P)mprintf('\ndeterminant of P is =%1.2f\n\n',d)
if d==2.961e-17 thenmprintf('since determinant of C is zero therefore its inverse does not exist \nhence given matrix is not digonlisable\n')
elseQ=inv(P) // inverse pB=Q*A*P //diogonal matrix
mprintf('P^-1*A*P=\n')disp(B)if B==D then mprintf('given matrix is diagonlisable\n')else mprintf('given matrix is not digonlisable')endend
41
CONSOLE-Coloumn of P are eigen vector of matrix A and P= - 0.7071068 0.7071068 0. 0.7071068 0.7071068 0. 0. 0. 1.
digonlisable matrix D is D= 0. 0. 0. 0. 2. 0. 0. 0. 2.
42
determinant of P is =-1.00
P^-1*A*P= 0. 0. 0. 0. 2. 0. 0. 0. 2. given matrix is diagonlisable
43
EXPERIMENT 8(b)
AIM- Write a scilab code to determine whether the given matrices are diagonalizable or not, and if diagonalizable then show thatP-1AP=D
A=[1 0 11 2 00 0 3 ]
EDITOR- clcA= [1 0 1;1 2 0;0 0 3]
[P,D]=spec(A)
44
mprintf('Coloumn of P are eigen vector of matrix A \n')mprintf(' and \n P=\n')
disp(P) //pmprintf('\ndigonlisable matrix D is\n D=')disp(D)d=det(P)mprintf('\ndeterminant of P is =%1.2f\n\n',d)
if d==2.961e-17 thenmprintf('since determinant of C is zero therefore its inverse does not exist \nhence given matrix is not digonlisable\n')
elseQ=inv(P) // inverse pB=Q*A*P //diogonal matrix
mprintf('P^-1*A*P=\n')disp(B)if B==D then mprintf('given matrix is diagonalizable\n')else mprintf('given matrix is not diagonalizable')endend
45
CONSOLE-Coloumn of P are eigen vector of matrix A and P= 0 0.7071068 0.4082483 1. - 0.7071068 0.4082483 0 0 0.8164966
digonlisable matrix D is D= 2. 0 0 0 1. 0 0 0 3.
46
determinant of P is =-0.58
P^-1*A*P= 2. 0 0 0 1. 0. 0 0 3. given matrix is diagonalizable
47
EXPERIMENT 8(c)
AIM- Write a scilab code to determine whether the given matrices are diagonalizable or not, and if diagonalizable then show thatP-1AP=D
A=[1 2 30 2 30 0 2]
EDITOR- clcA= [1 2 3;0 2 3;0 0 2]
48
[P,D]=spec(A)mprintf('Coloumn of P are eigen vector of matrix A \n')mprintf(' and \n P=\n')
disp(P) //pmprintf('\ndigonlisable matrix D is\n D=')disp(D)d=det(P)mprintf('\ndeterminant of P is =%1.2f\n\n',d)
if d==2.961e-17 thenmprintf('since determinant of C is zero therefore its inverse does not exist \nhence given matrix is not digonlisable\n')
elseQ=inv(P) // inverse pB=Q*A*P //diogonal matrix
mprintf('P^-1*A*P=\n')disp(B)if B==D then mprintf('given matrix is diagonalizable\n')else mprintf('given matrix is not diagonalizable')endend
49
CONSOLE-Coloumn of P are eigen vector of matrix A and P= 1. 0.8944272 - 0.8944272 0 0.4472136 - 0.4472136 0 0 6.620D-17
digonlisable matrix D is D= 1. 0 0 0 2. 0
50
0 0 2.
determinant of P is =0.00
P^-1*A*P= 1. 0 0. 0 2. 0. 0 0 2. given matrix is diagonalizable
51
EXPERIMENT 8(d)
AIM- Write a scilab code to determine whether the given matrices are diagonalizable or not, and if diagonalizable then show thatP-1AP=D
A=[2 1 00 2 10 0 2 ]
EDITOR- clcA=[2 1 0;0 2 1;0 0 2]
[P,D]=spec(A)
52
mprintf('Coloumn of P are eigen vector of matrix A \n')mprintf(' and \n P=\n')
disp(P) //pmprintf('\ndigonlisable matrix D is\n D=')disp(D)d=det(P)mprintf('\ndeterminant of P is =%1.2f\n\n',d)
if d==2.961e-17 thenmprintf('since determinant of C is zero therefore its inverse does not exist \nhence given matrix is not digonlisable\n')
elseQ=inv(P) // inverse pB=Q*A*P //diogonal matrix
mprintf('P^-1*A*P=\n')disp(B)if B==D then mprintf('given matrix is diagonalizable\n')else mprintf('given matrix is not diagonalizable')endend
53
CONSOLE-Coloumn of P are eigen vector of matrix A and P= 1. - 1. 1. 0 4.441D-16 - 4.441D-16 0 0 1.972D-31
digonlisable matrix D is D= 2. 0 0 0 2. 0 0 0 2.
54
determinant of P is =0.00
P^-1*A*P= 2. 0 0 0 2. 0 0 0 2. given matrix is diagonalizable
55
EXPERIMENT 9(a)
AIM- Write a scilab code to determine whether the given operator is hermitian i.e. orthogonal or not
p=−iħ ∂∂x
EDITOR- clca=1P=[]//Finding hermitian matrixfor i=1:2
56
for j=1:2 if i==j then P(i,j)=0 elseif i==j+1 | j==i+1 P(i,j)=%i/2 else P(i,j)=0 end endendP(2,:)=-P(2,:)mprintf("\nThe matrix P is\n")disp(P)dx=1A=(1/dx)*[0 %i/2;-%i/2 0][ef,ev]=spec(A) ef1=ef'//dagger of eigen vector matrixX1=ef(:,1)//separating the eigen vectors X2=ef(:,2)XD2=X2' //calculating dagger X2E=XD2*X1 mprintf("\nX1*X2+ = %4.2f\n",E)
K=ef*ef1 //PxDagger(P)
//Checking Hermitianmprintf("\nThe product of eigen vector matrix and its hermitian is--\n")mprintf("%1.0f %1.0f\n",K)if abs(E)<0.001 & abs(det(K)-1)<0.001 then mprintf("The operator is orthogonal")else mprintf("The operator is not orthogonal")end
57
CONSOLE-The matrix P is 0 0.5i - 0.5i 0
X1*X2+ = 0.00
The product of eigen vector matrix and its hermitian is--1 00 1
58
The operator is orthogonal
59
EXPERIMENT 9(b)
AIM- Write a scilab code to determine whether the given operator is hermitian i.e. orthogonal or not
A= ∂2
∂x2
EDITOR-
clca=1L=[]
60
for i=1:3 for j=1:3 if i==j then L(i,j)=-2 elseif i==j+1 | j==i+1 L(i,j)=1 else L(i,j)=0 end endendmprintf("\nThe matrix L is\n")mprintf("%d %d %d\n",L)A=(1/a^2)*[-2 1 0;1 -2 1;0 1 -2][P,D]=spec(A) P1=P'//dagger of eigen vector matrixX1=P(:,1)//separating the eigen vectors X2=P(:,2)X3=P(:,3)XD2=X2' //calculating dagger X2XD3=X3' //calculating dagger X3E=XD2*X1 mprintf("\nX1*X2+ = %4.2f\n",E)F=XD3*X1mprintf("X1*X3+ = %4.2f\n",F)G=XD3*X2
mprintf("X2*X3+ = %4.2f\n",G)K=P*P1 //PxDagger(P)
//Checking Hermitianmprintf("\nThe product of eigen vector matrix and its hermitian is--\n")mprintf("%1.0f %1.0f %1.0f\n",K)
61
if abs(G)<0.001 & abs(F)<0.001 & abs(E)<0.001 & abs(det(K)-1)<0.001 then mprintf("The operator is orthogonal")else mprintf("The operator is not orthogonal")end
CONSOLE-
The matrix L is-2 1 01 -2 10 1 -2
X1*X2+ = -0.00X1*X3+ = -0.00X2*X3+ = 0.00
The product of eigen vector matrix and its hermitian is--
62
1 0 00 1 00 0 1The operator is orthogonal
63
EXPERIMENT 10AIM- To determine the principal moments and principal axis of moment of inertia of a dumbbell through diagonalisation
ω m L α l Ѳ lcosѲ l lsinѲ m
EDITOR- clc()
A Dumbbell is rotating
64
m=1//input("mass of dumble= ")l=1//input("length of dumble= ")for x=[0,%pi/6,%pi/4]M=2*m*l^2*[1 0 0;0 cos(x)^2 -sin(x)*cos(x);0 -sin(x)*cos(x) sin(x)^2][f,d]=spec(M)mprintf("@angle= %f \n",x) //check inverse exist or notif det(f)==0 then mprintf("inverse of v does not exist \n")else mprintf("inverse of v exist and det(f)= %f\n",det(f))end //check matrix is diagonalizabel or notD=f^-1*M*fif abs(D-d)<=0.0001 then mprintf("matrix can be diagonalizable \n")else mprintf("matrix can NOT be diagonalizable \n")end //find out principle momentum disp("principal momentum=")mprintf("L1= %f\n",d(1,1))mprintf("L2= %f \n",d(2,2))mprintf("L3= %f \n",d(3,3)) //find out princlipal axisdisp("first principal axies (X1)=")mprintf("%f \n",f(:,1))disp("Second principal axies (X2)=")mprintf("%f \n",f(:,2))disp("third principal axies (X3)=")mprintf("%f \n",f(:,3))mprintf("\n")end
65
CONSOLE-@angle= 0.000000 inverse of v exist and det(f)= -1.000000matrix can be diagonalizable principal momentum= L1= 0.000000L2= 2.000000 L3= 2.000000 first principal axies (X1)=
66
0.000000 0.000000 1.000000 Second principal axies (X2)= -0.000000 1.000000 0.000000 third principal axies (X3)= 1.000000 0.000000 0.000000
@angle= 0.523599 inverse of v exist and det(f)= -1.000000matrix can be diagonalizable principal momentum= L1= 0.000000L2= 2.000000 L3= 2.000000
67
first principal axies (X1)= 0.000000 -0.500000 -0.866025 Second principal axies (X2)= 0.000000 -0.866025 0.500000 third principal axies (X3)= 1.000000 0.000000 0.000000
@angle= 0.785398 inverse of v exist and det(f)= -1.000000matrix can be diagonalizable principal momentum= L1= 0.000000L2= 2.000000 L3= 2.000000
68
first principal axies (X1)= 0.000000 -0.707107 -0.707107 Second principal axies (X2)= 0.000000 -0.707107 0.707107 third principal axies (X3)= 1.000000 0.000000 0.000000
69
EXPERIMENT 11AIM- To determine the principal moments and principal axis of moment of inertia of a square plate through diagonalisation z
y
x
EDITOR- clc()M=[1/3 -1/4 0;-1/4 1/3 0;0 0 2/3][f,d]=spec(M)
70
//check inverse exist or notif det(f)==0 then mprintf("inverse of f does not exist \n")else mprintf("inverse of f exist and det(f)= %f\n",det(f))end //check matrix is diagonalizabel or notD=f^-1*M*fif abs(D-d)<=0.0001 then mprintf("matrix can be diagonalizable \n")else mprintf("matrix can NOT be diagonalizable \n")end //find out principle momentum disp("principal momentum=")mprintf("L1= %f\n",d(1,1))mprintf("L2= %f \n",d(2,2))mprintf("L3= %f \n",d(3,3)) //find out princlipal axis disp("first principal axies (X1)=")mprintf("%f \n",f(:,1))disp("Second principal axies (X2)=")mprintf("%f \n",f(:,2))disp("third principal axies (X3)=")mprintf("%f \n",f(:,3))mprintf("\n")
71
CONSOLE-inverse of f exist and det(f)= -1.000000matrix can be diagonalizable principal momentum= L1= 0.083333L2= 0.583333 L3= 0.666667 first principal axies (X1)= -0.707107 -0.707107
72
-0.000000 Second principal axies (X2)= -0.707107 0.707107 0.000000 third principal axies (X3)= 0.000000 0.000000 1.000000
73
EXPERIMENT 12AIM- To determine the principal moments and principal axis of moment of inertia of a cube through diagonalisation z
y
x
EDITOR- clc()n=3
74
M=((diag(ones(n-1,1),1))+(diag(ones(n-1,1),-1)))*(-1/4)+2/3*eye(n,n)//M=[2/3 -1/4 -1/4;-1/4 2/3 -1/4;-1/4 -1/4 2/3][f,d]=spec(M) //check inverse exist or notif det(f)==0 then mprintf("inverse of v does not exist \n")else mprintf("inverse of v exist and det(f)= %f\n",det(f))end //check matrix is diagonalizabel or notD=f^-1*M*fif abs(D-d)<=0.0001 then mprintf("matrix can be diagonalizable \n")else mprintf("matrix can NOT be diagonalizable \n")end //find out principle momentum disp("principal momentum=")mprintf("L1= %f\n",d(1,1))mprintf("L2= %f \n",d(2,2))mprintf("L3= %f \n",d(3,3)) //find out princlipal axis disp("first principal axies (X1)=")mprintf("%f \n",f(:,1))disp("Second principal axies (X2)=")mprintf("%f \n",f(:,2))disp("third principal axies (X3)=")mprintf("%f \n",f(:,3))mprintf("\n")
75
CONSOLE-inverse of v exist and det(f)= -1.000000matrix can be diagonalizable principal momentum= L1= 0.313113L2= 0.666667 L3= 1.020220 first principal axies (X1)= 0.500000
76
0.707107 0.500000 Second principal axies (X2)= -0.707107 -0.000000 0.707107 third principal axies (X3)= -0.500000 0.707107 -0.500000
77
EXPERIMENT 13(a)AIM- Write a scilab code to perform the given transformation using the appropriate transformation matrices
Scaling
EDITOR- clcclfx=[0:0.1:2*%pi]
78
y=sin(x)A=[x;y]a=1b=2//Scaling matrixS=[a 0;0 b]B=S*AX=B(1,:)Y=B(2,:)
//Plottinga=get("default_axes"); // get the handle of the model axes // setting its' propertiesf.background=4;f.auto_resize="off";a.x_location="origin";a.y_location="origin";
plot2d(x,y,3,leg='original')plot2d(X,Y,5,leg='Scaled by a factor of 2')xtitle('Scaled function')
GRAPHIC WINDOW-
79
80
EXPERIMENT 13(b)AIM- Write a scilab code to perform the given transformation using the appropriate transformation matrices
2-D Reflection
EDITOR- clcclfx=[0:0.1:2*%pi]y=cos(x)
81
A=[x;y]
//Reflection About Y-axisR=[-1 0;0 1]B=R*AX=B(1,:)Y=B(2,:)subplot(2,2,1)plot2d(x,y,3,leg='original')plot2d(X,Y,5,leg='reflected')xtitle('Reflection About Y-axis')
//Reflection About X-axisR=[1 0;0 -1]B=R*AX=B(1,:)Y=B(2,:)subplot(2,2,2)plot2d(x,y,3,leg='original')plot2d(X,Y,5,leg='reflected')xtitle('Reflection About X-axis')
//Reflection About Y=XR=[0 1;1 0]B=R*AX=B(1,:)Y=B(2,:)subplot(2,2,3)plot2d(x,y,3,leg='original')plot2d(X,Y,5,leg='reflected')xtitle('Reflection About Y=X')
//Reflection About Y=-XR=[0 -1;-1 0]B=R*AX=B(1,:)Y=B(2,:)subplot(2,2,4)plot2d(x,y,3,leg='original')
82
plot2d(X,Y,5,leg='reflected')xtitle('Reflection About Y=-X')
GRAPHIC WINDOW-
83
84
EXPERIMENT 13(c)AIM- Write a scilab code to perform the given transformation using the appropriate transformation matrices
Rotation
EDITOR- clcclfx=[0:2]y=x
85
A=[x;y] // rotation for angle 30 degreesubplot(1,2,1)t=-%pi/6R=[cos(t) sin(t);-sin(t) cos(t)]b=R*Aplot2d(x,y,3,leg='original')plot2d(b(1,:),b(2,:),5,leg='Rotated')xtitle('Rotation by 30 degree')a=get("current_axes")//get the handle of the newly created axesa.axes_visible="on"; // makes the axes visiblea.font_size=3; //set the tics label font sizea.x_location="origin"; //set the x axis positiona.y_location="origin"; //set the x axis position // rotation for angle 45 degreesubplot(1,2,2)t=-%pi/4R=[cos(t) sin(t);-sin(t) cos(t)]b=R*Aplot2d(x,y,3,leg='original')plot2d(b(1,:),b(2,:),5,leg='Rotated')xtitle('Rotation by 45 degree')a=get("current_axes")//get the handle of the newly created axesa.axes_visible="on"; // makes the axes visiblea.font_size=3; //set the tics label font sizea.x_location="origin"; //set the x axis positiona.y_location="origin"; //set the x axis position
86
GRAPHIC WINDOW-
87
88
EXPERIMENT 13(d)AIM- Write a scilab code to perform the given transformation using the appropriate transformation matrices
Translation
EDITOR-
89
clcclfx=[0:2]a=0b=2y=xq=[x;y;1 1 1]t=[1 0 a;0 1 b;0 0 1] c=t*qplot2d(x,y,3,leg='original')plot2d(c(1,:),c(2,:),5,leg='Translated')xtitle('translation of axis by a and b')
GRAPHIC WINDOW-
90
91
EXPERIMENT 14AIM- Wrie a scilab code to determine the principal strain and principal strain axis of given strain matrix
A=[ 54 34
34
54 ]
EDITOR- clcclfS=(1/4)*[5 3;3 5]//The two eigenvalues are the principal strain
92
//The corres eigenvector are principal strain axis which are X1and X2[P,D]=spec(S)mprintf("The two eigenvalues are the principal strain which are \nL1=%1.2f\nL2=%1.2f",D(1,1),D(2,2))mprintf("\n\nThe corresponding eigenvector are principal strain axis which are X1and X2")disp(P(:,1),'X1=')disp(P(:,2),'X2=')x=[-1:0.01:1]
y1=sqrt(1-x^2)y2=-sqrt(1-x^2)
plot2d(x,y1,5)plot2d(x,y2,5)plot2d(P(1,1),P(2,1),-2)plot2d(P(1,2),P(2,2),-2)a=get("default_axes"); // get the handle of the model axes // setting its' propertiesf.background=4;f.auto_resize="off";a.x_location="origin";a.y_location="origin";
B=S*[x;y1]C=S*[x;y2]
plot2d(B(1,:),B(2,:),2,leg='On Applying Strain')plot2d(C(1,:),C(2,:),2)p=D*Pplot2d(p(1,1),p(1,2),-3)plot2d(p(2,1),p(2,2),-3)
93
if S*P(:,1)-D(1,1)*P(:,1)<=0.1 then mprintf('\n\nS*X1=L1*X1\nVerified')end
if S*P(:,1)-D(1,1)*P(:,1)<=0.1 then mprintf('\n\nS*X2=L2*X2\nVerified')end
mprintf("\n\nSince by operating onn the EIgenvectors X1and X2\nThey are scaled by factors of L1 and L2 respectively")
CONSOLE-The two eigenvalues are the principal strain which are L1=0.50L2=2.00
The corresponding eigenvector are principal strain axis which are X1and X2 X1= - 0.7071068 0.7071068
94
X2= 0.7071068 0.7071068
S*X1=L1*X1Verified
S*X2=L2*X2Verified
Since by operating onn the EIgenvectors X1and X2They are scaled by factors of L1 and L2 respectively
95
GRAPHIC WINDOW-
96
EXPERIMENT 15
AIM- Write a scilab code to show the refraction effect of light beam from rarer to denser medium using transformation matrix and to verify Snell’s law.
EDITOR- clc()clf()i=%pi/15mprintf("\nIncident angle is=%1.2f\n",i)x=[-5:0]
97
y=tan(i)*xplot(x,y,'r')u1=1u2=1.5r=[1 0;0 u1/u2]x=[0:5]p=r*[x;tan(i)*x]
plot(p(1,:),p(2,:))slope=(p(2,2)-p(2,1))/(p(1,2)-p(1,1))r=atan(slope)mprintf("\nRefraction angle by slope of refracted line=%1.2f\n",r)plot([-5:5:5],[0 0 0],'k--')plot([0 0 0],[-1:1],'k')
hl=legend(['Incident light';'Reflected light';'Normal';'Separation between two medium'],2);
if u2/u1-sin(i)/sin(r)<=0.1 then mprintf("\nSnells Law is verified\nas u2/u1 =~ sin i/sin r\n")end
r=asin((u1/u2)*sin(i))mprintf("\nRefraction angle by snell law is=%1.2f\n",r)
98
CONSOLE-Incident angle is=0.21
Refraction angle by slope of refracted line=0.14
Snells Law is verifiedas u2/u1 =~ sin i/sin r
Refraction angle by snell law is=0.14
99
100
GRAPHIC WINDOW-