Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

NAME – AKSHAY BORA

ROLL NO. -7682

PRACTICAL EXAM
QUESTION NO. 1:
PROGRAM:
clc
funcprot(0)
clear
sigma = [0.1,0.05,0.01] //Defining the range for given values of sigma
x = [0:0.001:2] // This defines the range of x, the plot is symmetric around 1 i.e.,
The mean of the normal distribution is 1 so the range is taken form 0 to 2
(symmetric around 1)
colour = ["-r","-m","-k"] // This is defined to give plot the desired colors.
for i=1:3 // Using a for loop for i = 1 to i =3, since the stepsize is not defined
program takes it to be 1.
s = sigma(i)
c = colour(i)
function Normal=f(x, s) //Defining the required function
Normal = (1/(s*sqrt(2*%pi)))*exp(-((x-1)^2)/(2*s*s))
endfunction
plot(x,f,c)//Gives the required plot; since the loop iterates thrice, for three values
of "f" three plots are acheived.
end//Ending the for loop
xgrid(5,1,7) // Gives the grid to the plot
legend(["For s = 0.1","For s = 0.05","For s = 0.01"]) //Giving a proper legend
xlabel("The values of x --->>","fontsize",5) //For label on the x axis
ylabel("The values of the function --->>","fontsize",5) //For label on the y axis
title("Approximating Normal Distribution into DIRAC DELTA
function","fontsize",6)//For title
// integrating the function
for j = [1:3]
s = sigma(j)
I = intg(-3,5,f,0.0001)
disp(I,"The value of integral for s = "+string(s))
end

RESULT:
CONSOLE OUTPUT:

The value of integral for s = 0.1

1.

The value of integral for s = 0.05

1.

The value of integral for s = 0.01

1.

QUESTION NO .2

PROGRAM:
clc
clear
x = [-4:0.001:4] //Range of x;
l = 3 // limit of integral
sigma = [0.01,0.005] //Since the values of sigma arent given, I take them to
be 0.01 and 0.05 which are considerably low
for i = [1:2] // The For loop iterates twice
s = sigma(i)
function normal=f(x, s) // Defining the function as given (x+2)*delta
normal = (x+2).* (1/(s*sqrt(2*%pi)))*exp(-((x-1)^2)/(2*s*s))
endfunction
I = intg(-l,l+2,f) //Finding the integral within the proper limits
disp(I,"Integral of the function for s = "+string(s)+" is :") //displays the
result.
end //Ends the FOR loop

RESULT:
CONSOLE OUTPUT:

Integral of the function for s = 0.01 is :

3.

Integral of the function for s = 0.005 is :

3.
ANALYTIC OUTPUT:
QUESTION No .3
PROGRAM:
clc
clear
x = [-4:0.001:4] //Range of x
l = 1 //Limit of integral
sigma = [0.01,0.005] //SInce the values of sigma arent given, I take them to
be 0.01 and 0.05 which are considerably low
for i = [1:2] //For loop gives 2 iterations
s = sigma(i)
function normal=f(x, s) //The required function is defined using this
normal = (x-1).* (1/(s*sqrt(2*%pi)))*exp(-((x-1)^2)/(2*s*s))
endfunction
I = intg(-1-l,-1+l,f) //Finds the integral
disp(I,"Integral of the function for s = "+string(s)+" is :") //Displays the
output
end //Ends the for loop

RESULT :
CONSOLE OUTPUT :
Integral of the function for s = 0.01 is :
0.

Integral of the function for s = 0.005 is :

0.

ANALYTIC RESULT :

You might also like