Practice Questions 2024 April
Practice Questions 2024 April
1. Write a MATLAB® code to create a 3 × 3 matrix filled with random numbers. Slice
the matrix to extract the middle row and last column. Using these vectors, write a
MATLAB® function to calculate the dot product of two vectors, without using the
built-in dot function.
2. Generate a 5×5 matrix with sequential numbers from 1 to 25. Slice the matrix to obtain
a 2 × 2 matrix from the top-left corner and another from the bottom-right corner.
3. Create a MATLAB® script to calculate the factorial of a given integer using a for loop.
4. Write a MATLAB® function named RootMeanSquare to calculate the root mean square
(RMS) of an input vector.
5. Write a MATLAB® script to find the prime numbers within a given range using a while
loop.
6. Write a MATLAB® function to compute the angle between two vectors using the dot
product. You may use to the DotProduct function defined in question 1.
8. Develop a MATLAB® script to find the greatest common divisor (GCD) of two numbers
using the Euclidean algorithm within a while loop.
Also, show the percentage relative error by comparing it with the analytical value.
10. Develop a MATLAB® script to generate a parametric plot of a cycloid curve defined by
the equations:
where r is the radius of the generating circle and t varies from 0 to 4π. Customize the
plot by adding a title, axis labels, and setting appropriate limits for the axes.