BSP Lab-1
BSP Lab-1
1 2 3 1 0
4 5 6 2 5
7 8 9 3 3
6 7 8
9 10 11
12 13 14
Try c=a+b; and comment on the result
-------------------------------------------------------------------------------------------------------------------------------------------
Prepared by: Dr. Md. Asadur Rahman, Assistant Professor, Dept of Biomedical Engineering, MIST
Military Institute of Science and Technology (MIST)
Department of Biomedical Engineering
_________________________________________________________________________
2.2 Matrix Subtraction: Just using the simple subtraction sign (-) you can subtract two matrices of
same length. An example is given:
Type in Matlab Response by Matlab
m=[1 2 3; 4 5 6; 7 8 9]; p =
n=[1 3 4; 4 2 3; 9 3 1];
p=m-n 0 -1 -1
0 3 3
-2 5 8
Try c=m-b; and comment on the result
2.3 Matrix Multiplication: There are two types of multiplication in Matrix- scalar multiplication and
vector multiplication. Here both example are given:
Scalar Multiplication
Type in Matlab Response by Matlab
m=[1 2 3; 4 5 6; 7 8 9]; p =
p=m*2
2 4 6
8 10 12
14 16 18
Vector Multiplication
Type in Matlab Response by Matlab
m=[1 2 3; 4 5 6; 7 8 9]; p =
n=[1 3 4; 4 2 3; 9 3 1];
p=m*n 36 16 13
78 40 37
120 64 61
Try p=m.*n; and comment on the result
2.4 Matrix Division: Matrix division is generally done for scalar division. This operation is easy. On
the other hand, vector division is associated with linear algebra. Follow class instruction to
understand these.
Scalar Division
Type in Matlab Response by Matlab
m=[1 2 3; 4 5 6; 7 8 9]; p =
p=m/2
0.5000 1.0000 1.5000
2.0000 2.5000 3.0000
3.5000 4.0000 4.5000
Vector Division
A = [1 1 3; 2 0 4; -1 6 -1]; x =
B = [2 19 8];
x = B/A 1.0000 2.0000 3.0000
Be introduced with inverse and transpose functions. Also learn about
the length and size of a matrix
-------------------------------------------------------------------------------------------------------------------------------------------
Prepared by: Dr. Md. Asadur Rahman, Assistant Professor, Dept of Biomedical Engineering, MIST
Military Institute of Science and Technology (MIST)
Department of Biomedical Engineering
_________________________________________________________________________
3. Subscripting
Individual elements in a matrix are denoted by a row index and a column index. To pick out any
specific vector its row and column index are necessary and vice versa. Examples are given.
Type in Matlab Response by Matlab
u = rand(1,5) u =
u(3)
[R C]=find(u,0.1763) 0.8147 0.9058 0.1270 0.9134 0.6324
-------------------------------------------------------------------------------------------------------------------------------------------
Prepared by: Dr. Md. Asadur Rahman, Assistant Professor, Dept of Biomedical Engineering, MIST
Military Institute of Science and Technology (MIST)
Department of Biomedical Engineering
_________________________________________________________________________
-------------------------------------------------------------------------------------------------------------------------------------------
Prepared by: Dr. Md. Asadur Rahman, Assistant Professor, Dept of Biomedical Engineering, MIST
Military Institute of Science and Technology (MIST)
Department of Biomedical Engineering
_________________________________________________________________________
7. Basic Graphics
The bread-and-butter of Matlab graphics is the ‘plot’ command. Earlier we produced a plot of the sine
function
x = 0:.1:2*pi;
y = sin(x);
plot(x,y)
a) plot(x,y,’r-.’)
b) plot(x,y,’bx’)
c) plot(x,y,’b:x’)
d) plot(x,y,x,2*y)
e) plot(x,y,x,2*y,’--’)
f) plot(x,y);
hold on
plot(5*x,5*y)
Subplotting
To plot more than one set of axes in the same window, use the subplot command. You can type
subplot (row_pos,col_pos,fig_number)
Example:
t = 0:.1:2*pi;
subplot(2,2,1)
plot(cos(t),sin(t))
subplot(2,2,2)
plot(cos(t),sin(2*t))
subplot(2,2,3)
plot(cos(t),sin(3*t))
subplot(2,2,4)
plot(cos(t),sin(4*t))
t = 0:.1:2*pi;
plot3(cos(3*t),sin(3*t),t)
rotate3d
Learn also about: axes labelling, legend, title, grid, box, linespace.
-------------------------------------------------------------------------------------------------------------------------------------------
Prepared by: Dr. Md. Asadur Rahman, Assistant Professor, Dept of Biomedical Engineering, MIST
Military Institute of Science and Technology (MIST)
Department of Biomedical Engineering
_________________________________________________________________________
Home Works:
1. Create a structure variable including all of your academic information like Name, Roll, Dept,
Level, etc.
x=12 + 32 + 52 + . . . + 252
i) 20!
1 15 i 2 2i 30
ii) x
10 i 1 i3
-------------------------------------------------------------------------------------------------------------------------------------------
Prepared by: Dr. Md. Asadur Rahman, Assistant Professor, Dept of Biomedical Engineering, MIST