PSLP FILE
PSLP FILE
Objective:
Installation of MATLAB and demonstration of simple programming concepts like matrix
multiplication (scalar and vector), loop, conditional statements and plotting.
Formulation:
MATLAB Installation:
MATLAB Download
• Run the installer and follow the on-screen instructions to install MATLAB on your
computer.
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.
Method:
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.
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.
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:
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:
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.
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.
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:
Formula:
Code:
Output:
Learning outcome:
Objective:
Fitting of binomial distribution after computing mean and variance.
Formula:
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.