0% found this document useful (0 votes)
21 views29 pages

PSLP FILE

The document outlines a series of experiments using MATLAB to demonstrate programming concepts and statistical distributions. It covers installation, basic operations like matrix multiplication, loops, and plotting, along with theoretical probability limits, normal and exponential distributions, and binomial distribution fitting. Each experiment includes objectives, methods, and learning outcomes to enhance understanding of MATLAB and statistical concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views29 pages

PSLP FILE

The document outlines a series of experiments using MATLAB to demonstrate programming concepts and statistical distributions. It covers installation, basic operations like matrix multiplication, loops, and plotting, along with theoretical probability limits, normal and exponential distributions, and binomial distribution fitting. Each experiment includes objectives, methods, and learning outcomes to enhance understanding of MATLAB and statistical concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

EXPERIMENT 1

Objective:
Installation of MATLAB and demonstration of simple programming concepts like matrix
multiplication (scalar and vector), loop, conditional statements and plotting.
Formulation:

1. MATLAB, short for MATrix LABoratory, is a high-performance programming language


and numerical computing environment widely used in various fields such as engineering,
physics, finance, and signal processing. Developed by MathWorks, MATLAB provides a
comprehensive set of tools for data analysis, visualization, and algorithm development.

MATLAB Installation:

Go to the official MATLAB website and download the installer:

MATLAB Download

• Run the installer and follow the on-screen instructions to install MATLAB on your
computer.

3. Open MATLAB, launch it after the installation is complete.

4. The Scripting Area in MATLAB is where users create, edit, and run script files
containing sequences of MATLAB commands. These files, typically written in the
MATLAB programming language, enable users to automate tasks, develop algorithms,
and organize code for efficient execution. The Scripting Area enhances code modularity
and reusability MATLAB. 5. The Command Window

MATLAB serves as an interactive interface where users enter and execute commands. It
allows for real-time execution of code, immediate feedback on calculations, and
exploration of data. Users can perform tasks, debug code, and obtain results, making it a
central component for MATLAB programming and analysis.

6. The Workspace in MATLAB is a visual representation of the current workspace


variables, providing information about their values and properties. It serves as an
interactive environment for managing and inspecting data during a session. Users can
manipulate variables, explore data structures, and monitor changes, facilitating efficient
data analysis and debugging.

7. Open editor and WAP for the following:

a. Multiplication of a matrix with a scalar.

b. Multiplication of a matrix with a matrix (scalar product).

c. Multiplication of a matrix with a matrix (vector product).

d. Loop 5 times and print if the number is odd or even.

e. Plot (2D) the square function (squares of 1 to 10).

Method:

1) Open the MATLAR software

2) Go to command window to write the program or


3) Open a new script & save it
A. Multiplication of a matrix with a scalar.

Steps:

1. Take any matrix of order (m*n, the one we're taking is of 2*3) and assign it to a
variable, let it be mat.

2. Take any numerical (or, scalar) value and assign it a variable, let it be x.

3. Apply multiplication operation on the variables assigned above and the let the
result be equal to another variable, res.

4. Display result.
B. multiplication of matrices(vector product)
Steps:

1. Consider two matrix, c and d (order m*n, here we are taking it as 2*2), and
assign values to them.

2. Apply multiplication operation on them. Consider a variable (s_prod here) and


assign the value of that operation to it, to store the result in it.

3. Display the result


C. Display numbers ranging from 1 to 20 are even or odd using MATLAB.
d. WAP to find largest of three numbers.
E. WAP to accept a coordinate point in a XY plane and determine a quadrant of that
point.
Output:
Learning Outcome:

This experiment helped me to understand the functioning of MATLAB and its various
components. We used MATLAB to perform various experiments which gave us
understanding of vector and scaler product of matrix. Use of loops and conditional
statement and to determine a coordinate point in a XY plane and determine a quadrant
of that point.
EXPERIMENT 2

Objective:
Program for demonstration of theoretical probability limits.

Steps:
1. Define the domain of the graph using a variable (let it be, n). Since we are required
to demonstrate probability limits so we plot the probability curve for various discrete
values of n.

2. Consider variables (let it be, p) and put them equal to zero for various values of n.

3. Run a for loop(i) from 1 to length of n.

4. Consider another variable (say tails) and put it equal to 0.

5. Run another loop(j) from 1 to first element of n.

6. Declare a random variable x using rand() function.

7. If x<0.5 increase tail by 1.

8. Calculate probability (p) by tail/n(i).

9. Plot the graph, using plot() function.

10. Title the graph and the axes appropriately.


CODE:
Output

Learning outcome:

Through this experiment, we observed that as the number of trials increases, the
observed frequency stabilizes. Using a coin toss, where the probability of getting tails
(p(tail)) is 1/2, the expected frequency of tails is approximately achieved after around
500 tosses.
EXPERIMENT 3
Objective:

Program to plot normal distributions and exponential distributions for various


parametric values.

1. Plotting of Normal Distribution for various parametric values.

Formula

Where.
x is the variable
µ is the mean
σ is the standard deviation
Steps:
1. Define the range of the graph using a variable, say 'x'. To plot a
graph from -20 to 20 with a step size of 0.01, use x = -
20:0.01:20.
2. Set 'mu' and 'sig1' as the mean and standard deviation of the
normal distribution, respectively.
3. Create another variable, 'y', and use the normpdf(x, mu, sig1)
function to generate the normal distribution curve. Here, 'x' is
the random variable, and 'mu' and 'sig1' are the mean and
standard deviation of the distribution. The normpdf function
takes 'x', 'mu', and 'sig1' as arguments.
4. Plot the graph using the plot() function.
5. Add appropriate titles to the graph and axes.
6. Use the hold on function to enable multiple plots on the same
figure.
7. Repeat the previous steps to plot multiple normal distribution
curves with different values for 'mu' and 'sig1'.
Code
Output
2. Plotting of Exponential Distribution for various parametric values.

Formula:

λ is the scale parameter

x is the random variable

Steps:

1 Define the domain of the graph using a variable 'x'. Since we are required to plot a
graph from -20 to 20 with a step size of 0.01, x = -20:0.01:20.

2 Consider the variable 'lambda' as the parameter of the exponential distribution.

3 Consider another variable 'y'. Use the exppdf(x, 1/lambda) operation to plot the
exponential distribution curve. Here, 'x' is the random variable and 1/lambda is mu. 'x'
and 1/lambda are the arguments of the xppdf function.

4 Plot the graph using the plot() function.

5 Title the graph and the axes appropriately.

6 Use the hold on function to draw multiple plots in the same window.

7 Repeat the above steps to plot multiple exponential distribution curves for different
values of lambda.
Code:
Output:

Learning outcome:

This experiment helped us understand how the values of the normal distribution change
for different values of sigma by plotting curves while keeping mu constant. The bell
shape has a higher peak for smaller sigma values, while it flattens as sigma increases.
We also observed that when mu changes, the position of the peak shifts.

Additionally, we saw that for various values of lambda, the exponential distribution
changes, with higher lambda resulting in a higher peak.
EXPERIMENT 4

Objective:

Fitting of binomial distribution for given n and p.

Formula:

n = the number of experiments


x = 0, 1, 2, 3, 4
p = Probability of Success in a single experiment
q = Probability of Failure in a single experiment = 1 – p

Question: Each sample of water has a 10% chance of containing a


particular organic pollutant. Assume that the samples are independent
regarding the presence of the pollutant.
(i) Find the probability that in the next 18 samples, exactly 2 contain
the pollutant.
(ii) Determine the probability that at least four samples contain the
pollutant.
Steps:
1. Consider a variable 'n' and set it equal to 18. This represents the
total number of trials.
2. Consider another variable 'p = 0.1', which is the probability that
a water sample contains a particular organic pollutant.
3. Consider another variable 'x' and set it equal to 2. This
represents the number of samples that contain the pollutant.
4. Consider another variable 'y' and set it equal to the binopdf(x, n,
p) function. Here, 'x' is the random variable, 'n' is the total
number of trials, and 'p' is the probability of success. These are
the arguments to this function. 'y' represents the probability
that exactly 2 out of 18 samples contain the pollutant.
5. Consider another variable 'a' that specifies the domain of the
trials.
6. Plot the graph using the plot() function.
7. Title the graph and label the axes appropriately.
8. Consider another variable 'z' and set it equal to the binocdf(x, n,
p) function. Here, 'x' is the random variable, 'n' is the total
number of trials, and 'p' is the probability of success. These are
the arguments to this function. 'z' represents the cumulative
distribution function.
9. Consider a variable and use it to calculate the probability of at
least 4 samples containing the pollutant.

Code:
Output:
Learning outcome:

In this experiment, we learned about the new function binopdf, which


is used to find the binomial distribution for given values of x, n, and p
as its arguments. We also used binocdf as the cumulative distribution
function for the binomial distribution, and plotted the graph using
plot, observing the results from the graph.
EXPERIMENT 5

Objective:
Fitting of binomial distribution after computing mean and variance.

Formula:

n = the number of experiments


x = 0, 1, 2, 3, 4
p = Probability of Success in a single experiment
q = Probability of Failure in a single experiment = l - p
Mean= np
Variance=npq

Question:
Given a table below find the probability distribution for the same and
expected frequency.
Steps:
1. Consider a variable x = [0, 1, 2, 3], which represents the possible
outcomes.
2. Consider another variable f = [36, 40, 22, 2], which represents
the frequency of their occurrence.
3. Consider another variable y = [1, 1, 1, 1].
4. Let n = 3, the number of trials.
5. Consider another variable f(x) = x .* f' to calculate the
summation of the product of f and x.
6. Let fi = gamma * f' to calculate the total number of trials.
7. Let mu = fix(i) / fi, which represents the mean.
8. Calculate the probability p using the formula mean = n * p for
the binomial distribution.
9. Let another variable q = 1 - p.
10.We know that variance = npq, so calculate it using the same
formula and store it in var.
11.Calculate the probability for various x using the binopdf(x, n, p)
function and store it in px. Here, x is the random variable, n is
the total number of trials, and p is the probability of success.
These are the arguments to this function.
12.Ex represents the expected values of x for n = 3 and Σfi = 100.
13.Plot the graph of x and the given frequencies using the stem()
function.
14.Plot the graph using the plot() function.
15.Title the graph and label the axes appropriately.
CODE:
Output:
Learning Outcome:
In this experiment, we found that the mean is calculated as the sum of
(fixi) divided by the sum of (fi). We also know that the mean is equal to
np for the binomial distribution, and the variance is given by npq. We
then calculated the probability using the binopdf function and the
expected frequency by multiplying the probability with the number of
trials. We used the plot function to plot the graph.

You might also like