Documente Academic
Documente Profesional
Documente Cultură
C = A*B
mxn
nxp
B
2
1 2 4
2
B 4
1
3 2 1 4 0 1
C A* B
1 2 2 4 4 1
10
x1 cars/hour
x2 cars/hour
400 cars/hour
600 cars/hour
or
1 1 x1 1200
0 1 x 1000
size (C)
gives the dimensions (m n) of C
max (C)
the maximum of each column
min (C)
the minimum in each column
9
sum (C)
sums each column
mean (C)
the average of each column
diag (c)
just the diagonal elements
C
tranpose the matrix
10
Matrices
A = pascal(3)
B = magic(3)
C = ones(3)
D = chol(A)
See help to find out more
11
Element-wise Multiplication
With 2D Arrays
In some applications we want to
perform an element-wise
multiplication, i.e. multiply each
element in the first array by the
corresponding element in the
second array. (In this case the two
arrays must be the same size.)
12
Contaminant Example
An environmental engineer is assessing
the levels of contaminant in the soil on
a polluted site. The contaminated area
has been divided into a grid and the
level of contaminant (C) has been
measured in each rectangle in the grid.
13
Contaminant Example
The array of contaminant levels (C)
has 6 rows and 5 columns so it will
be indexed with two indices. The
first index runs from 1 to 6, and
the second index runs from 1 to 5.
14
Contaminant Example
The data is entered with commas
separating columns, semi-colons
separating rows.
Contaminant Example
What is the total amount of
contaminant contained in the
polluted soil?
The concentration values have
units of g/cm3, so to work out the
total mass of contaminant in the
soil we need to first work out the
total volume of soil in each cell.
16
Contaminant Example
At this site we have an array of
data with the soil depth (in cm) in
each grid cell (depth to bedrock).
>> Depth = [ 285, 310, 320, 315, 300;
275, 305, 310, 320, 295;
270, 300, 300, 310, 280;
260, 290, 280 ,270, 255;
255, 285, 270, 265, 250;
250, 280, 265, 260, 240]
17
Element-wise Multiplication
To perform multiplication elementwise use a . before the operator,
e.g.:
3 1 0
4 2 1
A
B
1 2 4
0 1 3
3 4 1 2 0 1
C A. * B
1
4
12 2 0
2
12
18
20