(Msc. in Energy Engineering) 2012 Ec: by - Yihun Tefera
(Msc. in Energy Engineering) 2012 Ec: by - Yihun Tefera
Outline:
• What is Matlab ?
• Matlab Environment / Screen
• Variables & Arrays
• Some Symbolic commands and
Applications
2
What is Matlab
????
Stands for MATrix LABoratory
4
When Matlab Environment starts
1. You will briefly see a window that displays the
MATLAB logo as well as some product information,
and then
Launch Pad:
displays all the
tools and
applications
associated with
MATLAB;
7
Matlab as Scrach pad
It is just simple calculator
Matlab is interactive, no need to declare variables
>> 2+3*4/2
>> cos(pi)
>> abs(1+i)
>> sin(pi) 8
MATLAB utilizes the following arithmetic operators:
9
Variables
Initializing Variables
Syntax
Var = Expression
Where:
11
Variables (continued …)
To initialize variable with contents by simply typing the
variable name at the command prompt as:
>> T = 12
>>
>> T * 2
T=
24
>>
Vectors
Matrices
Linear algebra
13
Initializing Vectors
A row vector is created by an explicit list, starting with a left bracket, entering the
values separated by spaces (or commas) and closing the vector with a right bracket.
A column vector can be created the same way, and the rows are separated by
semicolons.
v is a row vector.
Example:
w is a column vector.
>> w = [1; 2; 4; 5]
14
Matrices
A Matrix :
is an array in two-dimensional,
having both multiple rows and multiple columns,
linear index
Indexing using parentheses
>> A(2,3)
10
Indexing submatrices using vectors of row and column indices
A(s) = s3 + 3s2 + 3s + 1
In MATLAB can be written as:
>> A = [ 1 3 3 1];
>> s =roots(A)
s= 19
Solutions to Systems of Linear Equations
Ax = b
20
Solutions to Systems of Linear
Equations (con’t…)
Solution by Matrix Inverse: Solution by Matrix Division:
Ax = b The solution to the equation
A-1Ax = A-1b Ax = b
x = A-1b can be computed using left division.
MATLAB: MATLAB:
>> A = [ 3 2 -1; -1 3 2; 1 -1 -1]; >> A = [ 3 2 -1; -1 3 2; 1 -1 -1];
>> b = [ 10; 5; -1]; >> b = [ 10; 5; -1];
>> x = inv(A)*b >> x = A\b
x= x=
-2.0000 -2.0000
5.0000 5.0000
-6.0000 -6.0000
Answer: Answer:
x1 = -2, x2 = 5, x3 = -6 x1 = -2, x2 = 5, x3 = -6
NOTE:
left division: A\b b A right division: x/y x y 21
Exercise: 1. Evaluate / compute the result of
i. X = 32 – (5+4) x 2 + √ (6 2.1+ 3)
ii. Y = e2 - log 2 + ln 20
ii.
log5x1 - 3x2 + ln x3 = 5
e2x1 + 2x2 - 3x3 + x4 = 1
log3x2 - 5x3 + 6x4 = -5
- x1 + 2x3 - (2.1)2 x4 = 0 22
Thank U
Q & A / Discussion
Session
????
23