You are on page 1of 10

University of Salahaddin-Hawler

College of Engineering
Software and Informatics Engineering Department
Second Year Class

Numerical Analysis
and
Probability
Matrix Continue

Lecturer
Kanar Shukr Muhamad

2023-2024
• 28th Feb 2024 Practical Exam: Mark on %10

All studied practical lectures

2
Matrix
❖r=roots(polynomialMatrix)

• Return root(s) of the polynomial, written its coefficients in

a matrix]
❖ p=poly(r)

• Return polynomial given its roots as a matrix parameter

❖ x=polyval(p,value)

 Substitute value in a polynomial p and return it.

3
Matrix
 The single quate(‘) transpose the given matrix

4
Matrix
 Matrix Addition or subtraction: can be done using +

and -

a = [1 2 3;1 2 3];

b = [1 1 1;2 2 2];

c=a+b % Matrix addition

d=a-b % Matrix subraction

5
Matrix
 Access matrix elements:

d=a(i1,j1)+b(i2,j2)
val=a(1,2)+b(1,2)

6
Matrix
 Matrix Multiplication using *

 Dimensions must agree.

>>a=[1 1 1 ; 1 1 1]
>> b=[1 2; 1 2;1 2]

%c[i][j]= c[i][j] + a[i][k] * b[k][j];

>> c=a*b

% c=

3 6
7
3 6
Scalar - Matrix Operations
» a=3;
» b=[1 2 3; 1 2 3];
b=
1 2 3
4 5 6
»c=a*b % Multiply each element of matrix b by a
c=
3 6 9
3 6 9
>>a+b %????
>>a-b %????
>>a/b %????
Matrix
 Element-by-element multiplication of two matrices,
dimensions must agree.

a = [1 3; 2 4];

b = [0 5; 10 2];

c = a.*b

% c=

0 15

20 8
9
Activities
 Q1/ Create a 3 by 3 matrix. Fill it with random values from 0 to 9,

using one MATLAB command.

 Q2/ Create a M function that takes a matrix named A, and return an

array contains all non zero values of the matrix A.

 Like:

 A= [1 2 3;3 4 0;0 4 0;0 5 0]

 Array=MF()

10 Array = [ 1 2 3 3 4 4 5]

You might also like