Matlab Programming Laboratory: X X X X X X X F
Matlab Programming Laboratory: X X X X X X X F
1. Create a uniformly distributed random number n in the range [1,10]. If n<5 compute n2,
otherwise log(n). Solve this problem in Matlab. Create a matrix 10-by-10 in the same way.
Indication:
Try to use rand, log, zeros (as functions) and if … else, for (as instructions).
2. For all the integer values from the range [-20, 20] compute:
x 3 − 12 x + 15, x < 0
f ( x) = x 4 + 4 x 2 + 15,0 ≤ x < 10
log10 ( x) + 10414, x ≥ 10
Solve this problem in Matlab and create a vector with all these 41 values.
Indication:
Try to use zeros (as function) and if … else… elseif, for (as instructions).
3. Create a program that asks you a positive integer in the range [1, 7]. The program will
display the corresponding day (1 – Monday, 2 – Tuesday …) or an error message for a wrong
number.
Indication:
Try to use input, fprintf (as functions) and switch… case… otherwise (as instructions).
4. Create a program that asks you a positive integer and display a corresponding message
(The number is / isn’t prime).
Indication:
Try to use input, fix, sqrt, rem, fprintf (as functions) and if…else, for, break (as instructions).
5. Create a program that asks you a positive integer n and display the value of n!
Indication:
Try to use input, fprintf (as functions) and while (as instruction).
-1-
6. Create a matrix A (20-by-10) with uniformly distributed random integer numbers in the
range [10,50]. Create matrices A1 and A2. Matrix A1 will have the odd rows and matrix A2
the even rows from matrix A. Add to matrix A1 a new column which will indicate the
position of the corresponding row to the initial matrix A. Make the same operations on matrix
A2.
Indication:
Try to use round, rand, size, rem (as functions) and if…else, for (as instructions).
7. Modify the previous program in the way that you can choose the dimension of matrix A.
Indication:
Try to use input, round, rand, size, rem (as functions) and if…else, for (as instructions).
8. Create a function that accepts as argument a matrix. This function creates a file (with the
same name as the matrix) in which it saves the content of the matrix.
Indication:
Try to use inputname, strcat, fopen, fclose size, fprintf (as functions) and for (as instruction).
-2-