0% found this document useful (0 votes)
2 views4 pages

Sheet 2

The document outlines various MATLAB functions for creating and manipulating matrices, including functions to generate matrices of zeros, ones, and identity matrices, as well as operations like finding maximums, minimums, and transposing. It provides examples of using these functions with a specific matrix A and includes an experiment section with questions related to matrix operations. The document serves as a guide for performing matrix analysis in MATLAB.

Uploaded by

rasha waleed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Sheet 2

The document outlines various MATLAB functions for creating and manipulating matrices, including functions to generate matrices of zeros, ones, and identity matrices, as well as operations like finding maximums, minimums, and transposing. It provides examples of using these functions with a specific matrix A and includes an experiment section with questions related to matrix operations. The document serves as a guide for performing matrix analysis in MATLAB.

Uploaded by

rasha waleed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Engineering Analysis Laboratory

Experiment [2]
Matrix Functions

Functions for Creating Matrices:

zeros Create an array of all zeros


ones Create an array of all ones
eye Identity matrix
rand Uniformly distributed random elements
randn Normally distributed random elements
magic Create special matrix

Functions for Matrices:


max Find the maximum of each colomn
min Find the minimum of each colomn
sum Find the summation of each colomn
Transpose (') Transpose the matrix
inv Matrix inverse
diag Diagonal of matrix
size Return array dimentions
fliplr Flip matrix left-right
flipud Flip matrix up-down
tril Lower triangular part of the matrix
triu Upper triangular part of the matrix
Rot90(A) Rotates matrix A counterclockwise by 90 degrees
Rot90(A, k) Rotates matrix A counterclockwise by k*90 degrees,
where k is an integer
fix Remove the fractional part from the matrix elements

Let us verify that using MATLAB. The first statement to try is

1
Engineering Analysis Laboratory

Let A=
16 3 2 13
5 10 11 8
9 7 6 9
4 15 14 1

>>sum(A)
ans=
34 35 33 31

>>A'
ans=
16 5 9 4
3 10 7 15
2 11 6 14
13 8 9 1

>>diag(A)
ans=
16
10
6
1

>>tril(A)
ans=
16 0 0 0
5 10 0 0
9 7 6 0
4 15 14 1

>>triu(A)
ans=
16 3 2 13
0 10 11 8
0 0 6 9
0 0 0 1

>> size(A)
ans=
4 4 (means that A has 4 rows and 4 columns)
>> fliplr(A)

2
Engineering Analysis Laboratory

ans =
13 2 3 16
8 11 10 5
9 6 7 9
1 14 15 4

>> flipud(A)

ans =
4 15 14 1
9 7 6 9
5 10 11 8
16 3 2 13

>>z = zeros(2,4)
z=
0 0 0 0
0 0 0 0

>> [m,n]=size(A)
m=
4
n=
4

>> f=5*ones(3,3)

f=
5 5 5
5 5 5
5 5 5

>> N=fix(10*rand(1,10))

N=
9 2 6 4 8 7 4 0 8 4

>>R=randn(1,4)
R=

0.2573 -1.0565 1.4151 -0.8051

3
Engineering Analysis Laboratory

Experiment:
Q1) What is the result of the following command:
>> Sum (A’)
>> Sum (A)’
>> Sum (diag (A))
>> Sum (triu (fliplr (A’)))
>> Sum (diag (flipud (A’)’)’)’
Q2) Given the array:
A=
1 4 3 2
4 1 2 5
3 3 5 1

Find the average of each column in A using MATLAB matrix functions.

You might also like