Lab Session 01
Lab Session 01
Lab Session 01
INTRODUCTION TO MATLAB
OBJECTIVES:
(a) To get acquainted with MATLAB’s environment
(b) To use MATLAB as a calculator
(c) To learn to initialize and manipulate vectors, matrices
(d) To learn to create MATLAB variables and basic plots
PRE-LAB THEORY
What is MATLAB?
MATLAB is a software program that allows you to do data manipulation and
visualization, calculations, math and programming. It can be used to do very
simple as well as very sophisticated tasks. It can solve large systems of equations
efficiently and it is therefore useful for solving differential equations and
optimization problems. It also provides excellent means for data visualization and
has symbolic capabilities. Whilst simple problems can be solved interactively with
MATLAB, its real power shows when given calculations that are cumbersome or
extremely repetitive to do by hand!
Matrix Operation:
>>A=[1 3 4 ; 5 7 8]
A=
134
578
>>2+A
Ans=
359
7 9 10
Element-by-element operations vs. Matrix Operations:
Matrix multiplication has a special procedure, and it is different from simple
element-to-element multiplication. This is unlike addition operation, where two
matrices cab be added by simple element-byelement addition, this is adding
corresponding elements of the two matrices in question. Thus, we have a special
set of operators that distinguish Matriz operations from element-by-element
operations. When you intend to perform matrix operation, you simply use, * for
multiplication, / for division, ^ for exponentiation and so on. But if you intend to
perform element-by-element operations, you have to use, .* for multiplication, ./
for division and .^ for exponentiation.
Example,
>>A=[2 3 4;5 6 7;2 1 0];
>>B=[1 2 3;5 6 2;0 0 5];
>>A*B
Ans=
17 22 32
40 52 59
7 10 8
>>A.*B
Ans=
2 6 12
25 42 12
0 0 0