0% found this document useful (0 votes)
15 views

Exos

Exos

Uploaded by

roumaissa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Exos

Exos

Uploaded by

roumaissa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exercise 1:

Enter the following Durer’s matrix using MATLAB Command Window.

Calculate:

1. The sum of different rows


2. The sum of different columns
3. The sum of the two main diagonals
4. Only the sum of third column
5. The mean value of the sum of different rows using the mean command
6. The mean value of the sum of different columns using the mean command

Exercise 2:

1 2 3 

1. Enter the following matrix: A = 2 3 1

 
 3 1 2
2. What are the results of the following commands?

>> A([2 3],[1 3])

>> A([2 3],1:2)

>> A([2 3],:)

>> A([2 3],end)

>> A(:)

>> A(5)

>> reshape(A(:),size(A))

3. Add a 4th column = [ 0 0 9 ]’ to matrix A.

1
4. Using the matrix A above, create the following matrix C using matrices concatenation.

Exercise 3:

(1) Create the row vector x = [1:10] and the column vector y = x' and the 10x10 matrix z = y*x

Now find the following:

- The number of elements in z with values greater than 10 but less than 90.
- The mean of all the values in z which do not lie along an edge of the matrix.

(2) Note that to find the first n elements in a matrix A that meet a given logical condition
L(A) with matlab, we can use the command: find(L(A),n). On the other hand, to find the
last n elements in a matrix A that satisfy the logical condition L(A), we can add a third
argument ’last’, that is we use the command find(L(A),n, ’last’).

- Create a 4-by-4 magic square matrix and find the first five elements that are less than
10. Then View those elements of A.
- Repeat the question for the last five elements.
- According to you, what will be the result of the matlab command:
[row,col]=find(A<10,5)

Exercise 4:

1. Enter these values into the vector X.


X=[17 8 12 15 6 11 9 18 16 10 13 19]
2. Calculate the length N of this vector using the command length(X).
3. Calculate the sum S of the elements of X.
4. Calculate X the average of X.

2
2

 ( X i − X ) and then the standard deviation


1 N
5. Calculate the variance of X:  =
2

N − 1 i =1
X

of X.
6. Calculate the differential vector dX =  X i+1 − X i  for i = 1,2, , N − 1 .

You might also like