ITC Lab File Cosmic ( (1) - 5 (1) 123
ITC Lab File Cosmic ( (1) - 5 (1) 123
Submitted by:
SUMIT JHA
23/EP/099
Submitted to:
Dr. AJEET KUMAR
Assistant Professor(Applied Physics)
VISION
MISSION
VISION
MISSION
e =
44 56 68
98 128 158
152 200 248
>> f = a.*b % Matrix multiplication (Element by element)
f =
2 8 18
24 40 60
70 96 126
>> g = linspace(1,50,20) %Creates 20 equally spaced values
g =
Columns 1 through 8:
1.0000 3.5789 6.1579 8.7368 11.3158 13.8947
16.4737 19.0526
Columns 9 through 16:
21.6316 24.2105 26.7895 29.3684 31.9474 34.5263
37.1053 39.6842
Columns 17 through 20:
42.2632 44.8421 47.4211 50.0000
>> h = 1:5:100 % Creates values with equal interval of 5
h =
Columns 1 through 16:
1 6 11 16 21 26 31 36 41 46 51 56
61 66 71 76
Columns 17 through 20:
81 86 91 96
>> i = a/b % Division of two matrices
i =
0.416667 0.166667 -0.083333
0.041667 0.166667 0.291667
-0.333333 0.166667 0.666667
e = 6
>>f = d(3,:) % to print a complete row
>>g = d(:,2) % to print a complete column
f =
7 8 9
g =
2
5
8
>> h = d(:,2:3) % to access two or more rows
>> i = d(2:3,1:2) % to print a sub matrix from a matrix
h =
2 3
5 6
8 9
i =
4 5
7 8
>> d(2,3) = 20 % to change an element of a matrix
d =
1 2 3
4 5 20
7 8 9
>> d(3,:) = [10 11 12] % to change a row of a matrix
d =
1 2 3
4 5 20
10 11 12
GRAPH -
EXPERIMENT -3:
AIM : Calculate the values of sine and cosine functions
using series solution approach
CODE
clc
clear all
x = input('Enter angle in radian')
fprintf(['Value of Sinx by inbuilt
function',num2str(sin(x)),'\n']);
sum = 0;
for n = 1:1:5
sin_func = ((-1)^(n-1))*(x^(2*n-1))/factorial(2*n-1);
% using series approach
sum = sum + sin_func;
end
fprintf(['Value of Sinx by series is',num2str(sum),'\n']);
error = abs( sin(x) - sum);
if error<= 0.001
% Check if the error is within the acceptable range
display('Verified')
else
display('Not Verified')
end
OUTPUT -
CODE FOR COSINE SERIES
clc
clear all
x = input('Enter angle in radian');
fprintf(['Value of Cosx by inbuilt
function',num2str(cos(x)),'\n']);
sum_cos = 0;
for n = 1:1:5
cos_func = ((-1)^(n-1))*(x^(2*n-2))/factorial(2*n-2);
sum_cos = sum_cos + cos_func;
end
fprintf(['Value of Cosx by series
function',num2str(sum_cos),'\n']);
error = abs( cos(x) - sum_cos);
if error<= 0.001
display('Verified')
else
display('Not Verified')
end
OUTPUT-
EXPERIMENT -4 :
AIM : Study the behaviour of Gaussian and Lorentzian
function using inbuilt plotting commands
CODE FOR 2-D GAUSSIAN CURVE
clc;
clear all;
x = linspace(-2, 2, 100);
% Generate 100 linearly spaced points between -2 and 2
z = (1/(sqrt(2*pi))) * exp(-(x.^2)/2);
% Calculate the Gaussian function values
plot(x, z) % Plot the Gaussian curve
xlabel('x') % Label the x-axis
ylabel('z') % Label the y-axis
title('Gaussian curve') % Add a title to the plot
2D GRAPH -
OUTPUT-
CODE
clc
clear all
A= 0.05;
w = 2;
delw = 0.002;
k = 0.2;
delk = 0.01;
x = -500:1:500;
% Generate 1000 linearly spaced points between 500 and 500
u1 = 2*A*cos((w*5)-(k.*x)).*cos((delw*5)-(delk.*x));
u2 = 2*A*cos((w*10)-(k.*x)).*cos((delw*10)-(delk.*x));
u3 = 2*A*cos((w*15)-(k.*x)).*cos((delw*15)-(delk.*x));
u4 = 2*A*cos((w*20)-(k.*x)).*cos((delw*20)-(delk.*x));
% Creates multiple plots in the same figure window
subplot(2,2,1);
plot(x,u1);
xlabel('Displacement');
ylabel('Amplitude');
title('Position of group wave at t=5s');
subplot(2,2,2)
plot(x,u1)
xlabel('Displacement');
ylabel('Amplitude');
title('Position of group wave at t=10s');
subplot(2,2,3)
plot(x,u1)
xlabel('Displacement');
ylabel('Amplitude');
title('Position of group wave at t=15s');
subplot(2,2,4)
plot(x,u1)
xlabel('Displacement');
ylabel('Amplitude');
title('Position of group wave at t=20s');
sgtitle('The Position of group waves at different times')
% Adds main title to the group of plots
OUTPUT-
CODE
clc
clear all
A= 0.05;
w = 2;
delw = 0.002;
k = 0.2;
delk = 0.01;
for t=0:1:20
x = -500:1:500;
% Generate 1000 linearly spaced points between 500 and 500
u = 2*A*cos((w*t)-(k.*x)).*cos((delw*t)-(delk.*x));
plot(x,u);
xlabel('Displacement')
ylabel('Amplitude')
title(['Propogation of group wave at t=', num2str(t)])
pause(0.2); % Creates time between the timing of loops
end
OUTPUT-
EXPERIMENT – 7
OUTPUT
Intensity distribution in single and double slit
CODE
clc;
clear;
e = 0.14*10^(-5);
d = 3*e;
A = 1;
theta = linspace(-500,500,1000);
lamb = 5500*10^(-10);
alp = pi*e*sind(theta)/lamb;
beta = pi*(e+d)*sind(theta)/lamb;
Is = A*((sind(alp)./alp).^2);
plot(theta,Is,'r')
xlabel('Angle in degrees')
ylabel('Intensity')
title('Intensity Distribution')
hold on; % holds the previous plot
Is = A*((sind(alp)./alp).^2).*(cosd(beta).^2);
plot(theta,Is,'k')
xlabel('Angle in degrees')
ylabel('Intensity')
title('Intensity Distribution')
OUTPUT
Finding missing orders in single and double slit
CODE
clc;
clear all;
e = 0.14*10^(-3);
d = 3*e
A = 1;
theta = linspace(-60,60,1000);
lamb = 5500*10^(-10);
alpha = (pi*e.*sind(theta))./lamb;
beta = (pi*(e+d).*sind(theta))./(lamb)
I = ((A.*(sind(alpha)).^2).*((cosd(beta).^2)./(alpha).^2));
Is= (A.*(sind(alpha)).^2)./(alpha).^2;
hold on
plot(theta,I);
xlabel('Theta','Fontsize',20);
ylabel('Intensity','Fontsize',20);
title('Intensity distribution in Single and double slit'
,'Fontsize',16);
plot(theta,Is);
gtext('Missing order is 4m')
gtext('Missing order is 4m')
hold off
OUTPUT
Intensity distribution in n-slits
CODE
clc;
clear all;
e = 0.14*10^(-3);
d = 3*e
A = 1;
n = 4;
theta = linspace(-60,60,1000);
lamb = 5500*10^(-10);
alpha = (pi*e.*sind(theta))./lamb;
beta = (pi*(e+d).*sind(theta))./(lamb)
I =
A.*(((sind(alpha).^2).*(sind(n.*beta).^2))./((alpha.^2).*(sind
(beta).^2)));
plot(theta,I);
xlabel('Theta','Fontsize',20);
ylabel('Intensity','Fontsize',20);
title('Intensity distribution in n slit' ,'Fontsize',18)
OUTPUT
Intensity distribution in single and double slit
(diffraction)
CODE
clear all;
e = 0.14*10^(-4);
d = 3*e
A = 1;
theta = linspace(-120,120,1000);
lamb = 5500*10^(-10);
alpha = (pi*e.*sind(theta))./lamb;
beta = (pi*(e+d).*sind(theta))./(lamb)
I = ((A.*(sind(alpha)).^2).*((cosd(beta).^2)./(alpha).^2));
Is= (A.*(sind(alpha)).^2)./(alpha).^2;
hold on
plot(theta,I);
xlabel('Theta','Fontsize',20);
ylabel('Intensity','Fontsize',20);
title('Intensity distribution in Single and double slit'
,'Fontsize',16);
plot(theta,Is);
hold off
OUTPUT
EXPERIMENT – 8
OUTPUT
OUTPUT
Roots of a Polynomial Equation using Bisection
method
CODE
clc
clear all
a = @(x) (x^3)-8*(x^2)+19*x-12;
% It creates a polynomial equation in x
minval = 1;
maxval = 10;
nosteps = 1000;
if(a(minval)*a(maxval) > 0)
display('no roots')
else
for i = 1:nosteps
midval = (minval+ maxval)/2;
if(a(midval)*a(maxval)>=0)
maxval = midval;
else
minval = midval;
end
end
end
fprintf("The root is %f\n",midval)
OUTPUT
clc
clear all
tspan=[0,2];
x0=0;
[t,x] = ode23("firstorder", tspan, x0);
%Use to solve nonstiff differential equation by lower order
method
plot(t,x);
xlabel('x', 'Fontsize', 12,'FontName','times new roman');
ylabel('Time', 'Fontsize', 12,'FontName','times new roman');
title('Ordinary Differential Equation', 'Fontsize',
18,'FontName','times new roman');
OUTPUT
Simultaneous Differential Equation
CODE
clc
clear all
tspan =[0,2];
u0 = 0.5;
v0 = 1;
z0 = [u0 ; v0];
[t,z] = ode23("simul_func", tspan, z0);
%Use to solve nonstiff differential equation by lower order
method
plot(t,z(:,1), t,z(:,2));
xlabel('z', 'Fontsize', 12,'FontName','times new roman');
ylabel('Time', 'Fontsize', 12,'FontName','times new roman');
title('Simultaneous Differential Equation', 'Fontsize',
18,'FontName','times new roman');
OUTPUT
Second Order Differential Equation for Pendulum
Problem
CODE
function z = pend(t,z) % Creates a function file
l = 1;
thetadot = z(2);
phidot = (-9.8/l)*sin(z(1));
zdot = [thetadot;phidot];
end
clc;
clear all;
tspan = [0,10];
theta0 = pi/4;
phi0 = 0;
z0 = [theta0,phi0];
[t,z] = ode23("pend",tspan,z0);
%Use to solve nonstiff differential equation by lower order
method
plot(t,z(:,1),t,z(:,2))
xlabel('t','FontSize',22,'FontName','Times New Roman');
ylabel('z','FontSize',22,'FontName','Times New Roman');
title('Differential Equation of Pendulum’,’Fontsize’,22,
'FontName','Times New Roman');
OUTPUT
EXPERIMENT – 10