MATLAB Problem Set 1_SP25
MATLAB Problem Set 1_SP25
Spring 2025
Note: The submission on Blackboard should include a ZIP folder containing 4 M-files (an M-file for each
problem) along with a report in .docx format. The folder should be named as MATLAB_PS1_Your names.
Problem 1
1. Find a short MATLAB expression (dynamic way) to build the matrix A defined as follows:
1 2 3 4 5 6 7
𝐴 = [9 7 5 3 1 −1 −3 ]
4 8 16 32 64 128 256
2. Give a MATLAB expression that uses only a single matrix multiplication with A to obtain:
b. Add 4 to just the odd-index rows of X (dynamic way) and save the new matrix in Z (can
be done in two commands).
c. Compute the square root of each element of matrix Z and save the new matrix in W.
Problem 2
Create a vector x with the elements,
(−1)𝑛+1 𝑛
𝑥𝑛 = 𝑛 = 1,2,3,4, … ,100
𝑛+1
Add up the elements of this vector.
1|Page
Problem 3
2 17 15 7 9
6 18 5 3 1
𝐴=[ ]
9 8 65 2 31
10 54 13 40 11
3. Convert A into a 5-by-4 matrix in two different ways. Store the resultant matrices in D and E.
4. Compute the inverse of each element of A and save the new matrix in F.
5. Add a random row to A and then compute its inverse. The random row should be composed of
random integer numbers from 2 to 20 (Use the randi command of MATLAB).
Problem 4
The probability density function (PDF) of the Rayleigh distribution is given in the expression below:
𝑥 (−𝑥22 )
𝑓 (𝑥, 𝜎) = 2 𝑒 2𝜎
𝜎
1. Define vectors x and f such as:
▪ x represents the interval [0;10] with step size of 0.001 (or 1e-3).
▪ f contains the values of the PDF function defined over the interval x (with 𝜎 = 1).
2. Plot the PDF of the Rayleigh distribution with the above specifications.
3. Using the numerical integration method, generate the array F which represents the cumulative
distribution function (CDF) of the Rayleigh distribution.
Note: The CDF is the integral of the PDF over the interval of x.
4. Plot on a new figure the CDF curve along with the PDF curve on the same graph.
2
Pr(0 < 𝑋 < 2) = ∫ 𝑓(𝑥, 1) 𝑑𝑥 ≈ 0.8648
0
Note: The answer to this question should be stored in a variable called Prob1.
2|Page
6. We define the random variable 𝑌 = 𝑡𝑎𝑛(𝑋 2 ) where X is a random variable following the
Rayleigh distribution. Using the numerical integration, show that the expected value of Y is:
10
𝐸[𝑌] = ∫ tan(𝑥 2 ) × 𝑓(𝑥, 1) 𝑑𝑥 ≈ 0.5281
0
Note: The answer to this question should be stored in a variable called Prob2.
3|Page