0% found this document useful (0 votes)
63 views23 pages

(Msc. in Energy Engineering) 2012 Ec: by - Yihun Tefera

This document provides an introduction to MATLAB. It discusses what MATLAB is, the MATLAB environment and screen layout, variables and arrays, and some basic symbolic commands and applications in MATLAB. MATLAB is a high-level programming language and environment used for numerical computation, visualization, and programming. It allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages.

Uploaded by

samuel mekuriaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views23 pages

(Msc. in Energy Engineering) 2012 Ec: by - Yihun Tefera

This document provides an introduction to MATLAB. It discusses what MATLAB is, the MATLAB environment and screen layout, variables and arrays, and some basic symbolic commands and applications in MATLAB. MATLAB is a high-level programming language and environment used for numerical computation, visualization, and programming. It allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages.

Uploaded by

samuel mekuriaw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

By - Yihun Tefera

(MSc. In Energy Engineering)


2012 EC
1
Introduction to MATLAB

Outline:

• What is Matlab ?
• Matlab Environment / Screen
• Variables & Arrays
• Some Symbolic commands and
Applications
2
What is Matlab
????
 Stands for MATrix LABoratory

 High level programming language

 Holds predefined function

 High level Solving Capacity 3


Matlab Environment
Start / Open Matlab Environment

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

2. MATLAB Desktop window will launch.


5
Matlab Environment
Contains:
1.Windows: Command Windows,
Work Space,
Current directory &
Command history

2. Bar: Title, Menu, tool

3. Other floating item/ buttons: Sizing, start, fn , 6


Display Windows (continued …)

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

>> a=5e-3; b=1; a+b

Most elementary functions and constants are already


defined

>> cos(pi)
>> abs(1+i)
>> sin(pi) 8
MATLAB utilizes the following arithmetic operators:

9
Variables
Initializing Variables
Syntax
Var = Expression

Where:

Var – the name of the variable

Expression - assign values


10
Variables (continued …)
Variable names:

 Must start with a letter

 May contain only letters, digits, and the underscore


“_”

 case sensitive, i.e. one & One are different variables.

 Matlab only recognizes the first 31 characters in a


variable name.

11
Variables (continued …)
 To initialize variable with contents by simply typing the
variable name at the command prompt as:

 Example – store a value of 12 in Variable name “ T ”

>> T = 12

>>
>> T * 2
T=
24
>>

To view the variable contents


simply typing the variable name at the command prompt
Arrays & its Operations

 Vectors

 Matrices

 Linear algebra

 Solutions to Systems of Linear Equations.

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.

Vectors (arrays) are defined as


 >> v = [1, 2, 4, 5]

 >> w = [1; 2; 4; 5]
14
Matrices
A Matrix :
 is an array in two-dimensional,
 having both multiple rows and multiple columns,

Its data element entry is similar to vector arrays:

 It begins with [ , and end with ]


 Spaces or commas are used to separate elements in a row
 Semicolon or enter is used to separate rows.

Example: Enter the given matrix A element values in Matlab

In Matlab entery of matrix,


A:
15
Matrix Reference (continued …)
A(1,1) 1st element
A(2,1) 2nd element
A(3,1) 3rd
full index A(4,1)
A(1,2)
4th
Consider a 4-by-3 matrix A(2,2) 5th
A(3,2) 6th
A(4,2) 7th
1 5 9 A(1,3) 8th
2 6 10 A(2,3) 9th
A(3,3) 10th
3 7 11
A(4,3) 11th
4 8 12
12th

linear index
Indexing using parentheses

>> A(2,3)
10
Indexing submatrices using vectors of row and column indices

>> A([2 3],[1 2]) 16


Some Basic Symbolic Commands
Sqrt – finds the square root of the expression
syntax : sqrt(x)
roots – finds the roots of polynomial expression
syntax : roots(f)
polyder – finds the derivative of the polynomial expression
syntax : polyder(x)

Simplify – simplify the polynomial expression


syntax : simplify(x) -
17
Some Basic Symbolic Commands

exp – the e power of the expression


syntax : exp(x) -

log – find the natural logarithm of the expression


syntax : log(f)

log10 – find the logarithm of base 10 expression


syntax : log10(f)
18
Basics: Algebraic expression
 The polynomials are represented by their coefficients in
MATLAB.

 Consider the following polynomial:

A(s) = s3 + 3s2 + 3s + 1
In MATLAB can be written as:
>> A = [ 1 3 3 1];

And to find the roots of this expression in Matlab

>> s =roots(A)
s= 19
Solutions to Systems of Linear Equations

Example: A system of 3 linear equations with 3 unknowns (x1, x2, x3):


3x1 + 2x2 – x3 = 10
- x1 + 3x2 + 2x3 = 5
x1 – x2 – x3 = -1
Let :
3 2 1  x1  10 
A   1 3 2  x   x2  b 5 
     
 1  1  1  x3   1

Then, the system can be described as:

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

2. Find the roots of :

iii. 2x4 + 4x2 – 6x + 9 = 0

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy