0% found this document useful (0 votes)
17 views

ITC Lab File Cosmic ( (1) - 5 (1) 123

Uploaded by

sumit jha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

ITC Lab File Cosmic ( (1) - 5 (1) 123

Uploaded by

sumit jha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Subject Code: EP-201

Subject Name: Introduction to Computing


Branch: Engineering Physics, 2nd Year(Third Semester)

Submitted by:
SUMIT JHA
23/EP/099

Submitted to:
Dr. AJEET KUMAR
Assistant Professor(Applied Physics)

Delhi Technological University, Shahbad Daulatpur,


Main Bawana Road, Delhi-110042
DELHI TECHNOLOGICAL
UNIVERSITY

VISION

To be a world class university through education, innovation and


research for the service of humanity.

MISSION

● To Establish Centres of Excellence in emerging areas of


science, engineering, technology, management and allied
areas.

● To Foster an Ecosystem for incubation, product


development, transfer of technology and entrepreneurship.

● To create environment of collaboration, experimentation,


imagination and creativity.

● To develop human potential with analytical abilities, ethics


and creativity.

● To provide environment friendly, reasonable and sustainable


solutions.
Department of Applied Physics

VISION

Consolidating teaching and learning processes covering all aspects of


pure and applied physics that promotes research and development
leading to the creation of new knowledge, inventions, and discoveries
fostering institute-industry linkages and entrepreneurial culture for
the betterment of all its stakeholders and society at large.

MISSION

M-1. To establish global and industry standards of excellence by


Generating new knowledge in all the endeavours concerned with
teaching, learning, research, and consultancy.
M-2. To help our students develop human potential, intellectual
Interest, and creative abilities and be lifelong learners to meet the
challenges of the national and global environment and be true
professional leaders.
M-3. To stand up to the needs and expectations of our society by
equipping and training our students to be good citizens, aware of their
commitments and responsibilities, to make this world a better place
to live.
M-4. To be a world-class centre for education, research, and
innovation in the various upcoming fields of Applied Physics.
M-5. To focus on the development of cutting-edge technologies and
to foster an environment of seamlessness between academia and
industry.
EXPERIMENT – 1:
AIM : Basics of Matrix operations and Matrix
manipulations
>> a = [1 2 3] % Creating a matrix
a =
1 2 3
>> a = [1 2 3; 4 5 6; 7 8 9] % Creating a 2-d matrix
>> b = [2 4 6; 6 8 10; 10 12 14]
a =
1 2 3
4 5 6
7 8 9
b =
2 4 6
6 8 10
10 12 14
>> c = a + b % Addition of two matrices
c =
3 6 9
10 13 16
17 20 23
>> d = a – b % Subtraction of two matrices
d =
-1 -2 -3
-2 -3 -4
-3 -4 -5
>> e = a*b % Multiplication of two matrices

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

>> j = a./b %Division of two matrices (Element by element)


j =
0.5000 0.5000 0.5000
0.6667 0.6250 0.6000
0.7000 0.6667 0.6429
>> a = zeros(4) % Create a zero square matrix of given order
a =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
>> b = ones(4) % Create a ones square matrix of given order
b =
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
>> c = eye(4) %Create a identity square matrix of given order
c =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
>> d = [1 2 3; 4 5 6; 7 8 9]
>> e = d(2,3) % to access a particular element in a matrix
d =
1 2 3
4 5 6
7 8 9

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

>> d(:,2) = [13; 14; 15] % to change a column of a matrix


d =
1 13 3
4 14 20
10 15 12
>> d(:,2:3) = [23 9; 8 17; 5 9]
% to change both row and column of a matrix
d =
1 23 9
4 8 17
10 5 9
>> d(2:3, 1:2) = [12 13; 13 12]
% to change specific elements of rows and columns
d =
1 23 9
12 13 17
13 12 9
EXPERIMENT -2:
AIM : Blackbody Radiation and verification of Wein’s
displacement law
CODE
clc;
clear all;
h = 6.626e-34; % Planck's constant (Joule-second)
c = 3e8; % Speed of light (meters/second)
k = 1.38e-23; % Boltzmann constant(Joule/Kelvin)
lamb = 1e-9:50e-9:2000e-9;
hold on
% Retain plots so multiple plots appear on the same figure
for T = 3500:500:5000
mew = (8*pi*h*c)./((lamb.^5).*(exp((h*c)./(lamb.*(k*T))-1)));
% Calculate energy density using Planck's law
[mmax,i] = max(mew);
% Find the maximum value of energy density and its index
lambmax = lamb(i);
% Find the wavelength corresponding to the max energy density
s = lambmax.*T;
error = abs(s-2.898e-3);
if error<=0.001
% Check if the error is within the acceptable range
display("Verified")
else
display("Not Verified")
end
plot(lamb,mew) % Plot the energy density vs. wavelength
plot(lambmax,mmax,'O','MarkerSize',8,'Markerfacecolor','r')
% Mark the peak point with a red circle text
(lambmax,mmax,['T= ',num2str(T),'k'],'FontSize',10)
% Annotate the plot with the temperature
end
xlabel("Wavelength(in m)") % Label the x-axis
ylabel("Energy Density(J/m^3)") % Label the y-axis
title("Blackbody Radiation") % Title of the plot
OUTPUT -

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 -

CODE FOR 3D GAUSSIAN CURVE


clc
clear all
x= linspace(-2,2,100);
% Generate 100 linearly spaced points between -2 and 2
y= linspace(-2,2,100);
% Generate 100 linearly spaced points between -2 and 2
[X,Y]= meshgrid(x,y);
Z=(1/(2*pi)*exp(-((X.^2+Y.^2)/2)));
surf(X,Y,Z); % Create a 3D surface plot
xlabel('X'); % Label the x-axis
ylabel('Y'); % Label the y-axis
zlabel('Z'); % Label the z-axis
title('Gaussian curve - 3d'); ) % Add a title to the plot
3 D GRAPH –

CODE FOR 2D LORENTZIAN CURVE


clc
clear all
x= linspace(-2,2,100);
% Generate 100 linearly spaced points between -2 and 2
gamma=1;
z=(1/(pi))*(gamma./((x.^2) + (gamma^2)));
plot(x,z);
xlabel('x'); % Label the x-axis
ylabel('z'); % Label the y-axis
title('Lorentz curve'); % Add title to the curve
2 D LORENTZIAN CURVE-
CODE FOR 3D LORENTZIAN CURVE-
clc
clear all
x= linspace(-2,2,100);
% Generate 100 linearly spaced points between -2 and 2
y= linspace(-2,2,100);
% Generate 100 linearly spaced points between -2 and 2
[X,Y] = meshgrid(x,y)
gamma=1;
Z = (1/(pi))*(gamma./((X.^2) + (gamma.^2)+ (Y.^2)))
%Calculate the Lorentzian function values
surf(X,Y,Z) % Create a 3D surface plot
xlabel('X') % Label the x-axis
ylabel('Y') % Label the y-axis
zlabel('Z') % Label the z-axis
title('Lorentz curve') % Add a title to the plot
3D LORENTZIAN CURVE-
EXPERIMENT -5:
AIM: MATLAB Program to find out the unknown
coefficients by polynomial fitting
CODE FOR DEGREE 2
clc; % Clear all variables
clear all % Clear the command window
format long e % Set display format to long exponential
x = [1 2 3 4 5 6 7 8]; % Data points for x
y = [1 4 12 16 25 30 49 64]; % Data points for y
degree = 2; % Degree of the polynomial for fitting
coefficients = polyfit(x,y,degree) );
% Find polynomial coefficients for the given degree
xi = linspace(1,8,1000);
% Generate 1000 linearly spaced points between 1 and 8
yi = polyval(coefficients,xi);
% Evaluate the polynomial at the points xi
plot(x,y,'o', 'Markersize',8,'Displayname', 'Data Points');
% Plot original data points
hold on;
% Hold the plot for adding the fitted curve
plot(xi,yi,'-r', 'Linewidth',2, 'Displayname', 'Fitted
Curve'); % Plot the fitted polynomial
xlabel('X'); % Label the x-axis
ylabel('Y'); % Label the y-axis
title(['Polynomial Fitting at degree ', num2str(degree)]);
% Add the title
legend('show'); % Show the legend
CURVE FOR DEGREE 2 :

CODE FOR DEGREE 3


clc; % Clear all variables
clear all % Clear the command window
format long e % Set display format to long exponential
x = [1 2 3 4 5 6 7 8]; % Data points for x
y = [1 4 12 16 25 30 49 64]; % Data points for y
degree = 3; % Degree of the polynomial for fitting
coefficients = polyfit(x,y,degree) );
% Find polynomial coefficients for the given degree
xi = linspace(1,8,1000);
% Generate 1000 linearly spaced points between 1 and 8
yi = polyval(coefficients,xi);
% Evaluate the polynomial at the points xi
plot(x,y,'o', 'Markersize',8,'Displayname', 'Data Points');
% Plot original data points
hold on;
% Hold the plot for adding the fitted curve
plot(xi,yi,'-r', 'Linewidth',2, 'Displayname', 'Fitted
Curve'); % Plot the fitted polynomial
xlabel('X'); % Label the x-axis
ylabel('Y'); % Label the y-axis
title(['Polynomial Fitting at degree ', num2str(degree)]);
legend('show'); % Show the legend
CURVE FOR DEGREE 3

CODE FOR DEGREE 5


clc; % Clear all variables
clear all % Clear the command window
format long e % Set display format to long exponential
x = [1 2 3 4 5 6 7 8]; % Data points for x
y = [1 4 12 16 25 30 49 64]; % Data points for y
degree = 5; % Degree of the polynomial for fitting
coefficients = polyfit(x,y,degree) );
% Find polynomial coefficients for the given degree
xi = linspace(1,8,1000);
% Generate 1000 linearly spaced points between 1 and 8
yi = polyval(coefficients,xi);
% Evaluate the polynomial at the points xi
plot(x,y,'o', 'Markersize',8,'Displayname', 'Data Points');
% Plot original data points
hold on;
% Hold the plot for adding the fitted curve
plot(xi,yi,'-r', 'Linewidth',2, 'Displayname', 'Fitted
Curve'); % Plot the fitted polynomial
xlabel('X'); % Label the x-axis
ylabel('Y'); % Label the y-axis
title(['Polynomial Fitting at degree ', num2str(degree)]);
legend('show'); % Show the legend
CURVE FOR DEGREE 5
EXPERIMENT – 6
AIM : MATLAB Code to show the propagation of
group wave as a function of time
CODE
clc
clear all
A= 0.05;
w = 2;
delw = 0.002;
k = 0.2;
delk = 0.01;
t = 5;
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) % plot the graph
xlabel('Displacement') % Label the x-axis
ylabel('Amplitude') % Label the y-axis
title('Position of Group Wave at t=5s ')
% Adds title to the curve

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

AIM : Write a MATLAB code to plot the intensity


distribution of single slit, double slit and n-slits.

Intensity distribution in single slit


CODE
clc;
clear all;
e = 0.14*10^(-3);
A = 1;
theta = linspace(-60,60,100); %creates equally spaced vectors
lamb = 5500*10^(-10);
alpha = (pi*e.*sind(theta))./lamb;
I = (A.*(sind(alpha)).^2)./(alpha).^2;
plot(theta,I) % plots the graph
xlabel('Theta','Fontsize',20) % Label the x axis
ylabel('Intensity','Fontsize',20) % Label the y axis
title('Intensity distribution in single slit' ,'Fontsize',16)
% Adds title to the plot
OUTPUT
Intensity distribution in double slits
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));
plot(theta,I)
xlabel('Theta','Fontsize',20)
ylabel('Intensity','Fontsize',20)
title('Intensity distribution in double slit' ,'Fontsize',16)

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

AIM : Write a MATLAB program to find the


roots of the equation by Bisection method

Use of Inbuilt function “roots”


CODE
clc
clear all
A=[3 -4 3 2 -2 5];
b = roots(A)

OUTPUT

Use of Inbuilt function “fzero”


CODE
clc
clear all
fx = @(x)(x^3)-(5*x)+1; % Creates a polynomial equation
z = fzero(fx,[0,1]) % use to find roots of the equation

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

Roots of a Transcendental Equation using


Bisection method
CODE
clc
clear all
a = @(x) tan(x)-(x); % creates a polynomial
minval = input("Enter the Minimum value");
maxval = input("Enter the Maximum value");
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

Multiple Roots of a given Equation using


Bisection method
CODE
clc
clear all
a = @(x) (x^3)-8*(x^2)+19*x-12;
minval = input("Enter the Minimum value\n");
maxval = input("Enter the Maximum value\n");
nosteps = 100000;
incre = (maxval-minval)/nosteps;
for i =1:nosteps
if(a(minval)*a(minval+incre))<0
midval = ((minval)+(minval+incre))/2;
fprintf("The Root is %f\n",midval);
else
end
minval = minval+incre;
end
OUTPUT
EXPERIMENT – 9

AIM : Write a MATLAB code to solve the second


order Differential Equation of Pendulum problem

First Order Differential Equation


CODE
function z = firstorder(x,t) % Creates a function file
z=x+t;
end

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

function zdot = simul_func(t,z) % Creates a function file


udot = -2*z(1) + 4*z(2);
vdot = 4*z(1) - 3*z(2);
zdot = [udot; vdot];
end

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

AIM : Write MATLAB programme to calculate


the maximum no. of modes supported by step
index optical fiber
CODE
clc;
clear all;
a_um = input('Enter the core radius of the fiber (in
micrometers): ');
% core radius in micrometers
lambda_um = input('Enter the input wavelength (in
micrometers): ');
% wavelength in in micrometers
n_core = input('Enter the refractive index of the core: ');
n_cladding = input('Enter the refractive index of the
cladding: ');
a = a_um * 1e-6; % core radius in meters
lambda = lambda_um * 1e-6; % wavelength in meters
% V parameter calculation
V = (2 * pi * a / lambda) * sqrt(n_core^2 - n_cladding^2);
fprintf('The V-parameter of the optical fiber is: %.3f\n', V);
% Condition loop for single mode and multimode
if V < 2.405
fprintf('The fiber operates in single-mode.\n');
M = 1; % single mode fibre
else
fprintf('The fiber operates in multimode.\n');
M = V^2 / 2; % Multimode fibre
fprintf('The number of modes supported by the fiber is
approximately: %.2f\n',M);
end
OUTPUT

You might also like