Você está na página 1de 35

Introduction

Introduction to Computing with MATLAB

Gemechu Fanta

Ambo University, Inservice Training


Program
October 26, 2011

1 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

outline
Introduction
First Step In Matlab
I
I

Getting Started
The Matlab Environment

Working With Matlab


I
I
I

Number Display Formats


Variables, Constants and Assignments
Basic Operations and Navigation
F
F
F

A) Scalar Operation
B) Vector/Matrix Operation
C) Command Window Navigation

Saving and Retrieving Data


Command, Algorithm and Program
Online help
2 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

Introduction

MATLAB is a program for doing numerical computation. It was


originally designed for solving linear algebra type problems using
matrices. Its name is derived from MATrix LABoratory
Powerful, extensible, highly integrated computation,
Widely used in engineering, mathematics and science
It has several advantages compared to other computational
environments like C, FORTRAN, in terms of solving engineering
and/or scientific problems

3 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

Introduction...
The MATLAB environment consists of families of application
specific packages that integrate with MATLAB system, various
sepcialized m-files designed to deal with particular/specific
problems.

4 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

Introduction...
The MATLAB environment consists of families of application
specific packages that integrate with MATLAB system, various
sepcialized m-files designed to deal with particular/specific
problems.
MATLAB is interactive software whose basic data element is an
array. An array does not require diemnsioning.

4 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

Introduction...
The MATLAB environment consists of families of application
specific packages that integrate with MATLAB system, various
sepcialized m-files designed to deal with particular/specific
problems.
MATLAB is interactive software whose basic data element is an
array. An array does not require diemnsioning.
Such an application-specific package is called a toolbox.

4 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

Introduction...
The MATLAB environment consists of families of application
specific packages that integrate with MATLAB system, various
sepcialized m-files designed to deal with particular/specific
problems.
MATLAB is interactive software whose basic data element is an
array. An array does not require diemnsioning.
Such an application-specific package is called a toolbox.
They are used for control theory, optimization, partial differential
equations, signal processing, symbolic computation, simulation
etc.

4 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

Introduction...
The MATLAB environment consists of families of application
specific packages that integrate with MATLAB system, various
sepcialized m-files designed to deal with particular/specific
problems.
MATLAB is interactive software whose basic data element is an
array. An array does not require diemnsioning.
Such an application-specific package is called a toolbox.
They are used for control theory, optimization, partial differential
equations, signal processing, symbolic computation, simulation
etc.
MATLAB is a case sensitive programming language that has
sophisticated data structures, built-in editing and debugging
tools.
4 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

1. First Step in MATLAB


MATLAB is a software package for numerical computing that
allows analysis of data, development of algorithms, building of
models that mimic real world phenomena and supports
visualization of desired results.
1.1 Getting Started
You can start MATLAB on MS windows platform in two ways.
If your computer has started already, then either you put the
cursor on the MATLAB Logo, i.e. the icon

which is availabel on your desktop and then double click


5 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

First...
or go to the start menu,
put your cursor on all
programs then follow
the links as shown in the
right.
to get the icon
,
finally double click it. In
either case, within a few
seconds MATLAB will
be evoked and you will
see a screen like the
following, the MATLAB
desktop.
6 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

First...
or go to the start menu,
put your cursor on all
programs then follow
the links as shown in the
right.
to get the icon
,
finally double click it. In
either case, within a few
seconds MATLAB will
be evoked and you will
see a screen like the
following, the MATLAB
desktop.
6 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

First...
This is the MATLAB
desktop/screen, composed of
three parts (as you see), The
Command window,
Workspace window and the
Command history window.
The MATLAB environment is
command oriented somewhat
like UNIX.
A prompt appears on the screen
and a MATLAB statement can
be entered.
7 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

First...
This is the MATLAB
desktop/screen, composed of
three parts (as you see), The
Command window,
Workspace window and the
Command history window.
The MATLAB environment is
command oriented somewhat
like UNIX.
A prompt appears on the screen
and a MATLAB statement can
be entered.
7 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

First...
When the < ENTER >key is pressed, the statement is executed,
and another prompt appears.
To close MATLAB go to File menu and then choose Exit
MATLAB or tye one of the commands quit or exit at the
MATLAB prompt and then hit return, i.e.
>> exit or >> quit or press keys ctrl-Q.
1.2. The MATLAB Environment
Basically, the MATLAB desktop environment has the following
window components
Command Window
Command History Window
Current Directory Window
MATLAB Path Window
Launch Pad Window
8 / 26
Workspace WindowGemechu Fanta Introduction to Computing with MATLAB

Introduction

9 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

First...
Command window, also
called MATLAB prompt
window, is the primary place
where you interact with
MATLAB. It is where you type
commands directly to the
MATLAB for execution.
The symbol >>, called
MATLAB prompt is displayed in
this window and afterwards a
cursor appears. A blinking
cursor signifies that MATLAB is
ready to accept and execute a
command.
10 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

First...
Command History Window
is a window that displays all
commands issued in MATLAB
since the recent past session,
i.e. all previous commands
executed in a MATLAB session.
It is useful for verification of a
computational sequence.
One can navigate through
command window from the
keyboard, using up-arrow,
down-arrow, left-arrow and
right-arrow. Up-arrow is used
to repeat previous commands.
11 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

First...

Launch pad window renders access


to all MATLAB toolboxes
Workspace Window is used to view
variable definitions along with variable
memory allocations and array type.
The entire variables of the most recent
operation are all available until you
execute the command, >> clear.
Editor Window is a window where we
write a code.

12 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

First...

Figure Window displays graphic


output from an m-file, a MATLAB
code. MATLAB directs graphics
output to a window that is different
from the command window.

13 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

2. Working with MATLAB


As a software package for numerical computing, MATLAB
recognizes three types of numbers,
I
I
I

Integer
Real
Complex

The MATLAB system has representations of the non numbers as


well Inf for e.g. generated by 1/0
NaN Not a Number, obtained from mathematically undefined
operations e.g. 0/0 or , factorial(171) etc
2.1 Number Display Formats
In MATLAB, a number can be displayed only in discrete form,
i.e. within a range and with a finite precision.
I
I
14 / 26

Integers can be displayed exactly,


Reals are represented by floating-point
Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

The default format is four digits after the decimal point. But if you
want to change it use
<< format long e
<< format short e
>> 1/3
>> 1/3
ans =
ans =
3.333333333333333e-001
3.3333e-001
>> 1.57
>> 1.57
ans =
ans =
1.570000000000000e+000
1.5700e+000
>> 4
>> 4
ans =
ans =
4
4

15 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

MATLAB Command
format short
format long
format short e
format long e
format short g
long g
+

bank
rat
16 / 26

Description
4 digits after the decimal point
14 digits after the decimal
5 digits and an exponent
Floating point format
with 15 digits.
Best of fixed or floating point
format with 5 digits
Best of fixed or floating point
format with 15 digits
The symbols +, - and blank are printed for
postitive, negative, and zero elements.
Imaginary parts are ignored.
Fixed formats for dollar and cents
Approximation by ratio of small integers

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

2.2 Variables, Constants and Assignments


A variable is a storage objectcontainer that can hold a value.
A constant is a quantity that never changes. A variable is
created by an assignment
>> x = 5
x=
5
Examples - how to assign values to three variables, x,y , and w.
It also shows that MATLAB response to the assignment
statements
>> y = pi4
y=
0.7854
>>w = y + x0.25
w=
2.2807
17 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

If you want to know all active/current variables you are working with,
just type the command who after the MATLAB prompt and press
return, you will get a list of currently active variables as under,
The value of a variable can be a scalar, any number or a
vector/matrix,
>> x = 91
x=
91
>> y = [2 1 3]
y=
23
>> z = [2 1 3;0 1 2]
z=
213
012
18 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

2.3 Basic Operations and Navigation

MATLAB works with basic


operations of arithmetic
[addition, subtraction,
multiplication and division], for
scalars directly [usual way] and
in case of vectors in two ways.
The following table summarizes
the symbol MATLAB accepts
for the operations

19 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

2.3 Basic Operations and Navigation

MATLAB works with basic


operations of arithmetic
[addition, subtraction,
multiplication and division], for
scalars directly [usual way] and
in case of vectors in two ways.
The following table summarizes
the symbol MATLAB accepts
for the operations

19 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

A) Scalar Operation

In order to carry out addition, subtraction, multiplication and division


of scalars, one can first enter the values at the MATLAB prompt as
follows
>> u = 5;
>> v = 3;
and then apply the operation directly
>> w = u + v >> x = u v >> y = u * v >> z = u/v
w=
x=
y=
z=
8
2
15
1.6667

20 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

B) Vector/Matrix Operation

As in the case of scalar-scalar multiplication, to carry out addition,


subtraction, multiplication and division of vectors/matrix by scalars,
first enter the values at the MATLAB prompt as follows
>> x = 3;
>> y = x + A >> z = x*A w=A/2
>> A= [2 0 6;4 2 0]
y=
z=
w=
A=
539
6 0 18
103
206
753
12 6 0
210
420

21 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

C) Command Window Navigation

If you want to recall


the most recent
command entered at
the prompt

22 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

C) Command Window Navigation

If you want to recall


the most recent
command entered at
the prompt

22 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

2.4 Saving and Retrieving Data


To save the data and retrieve use MATLAB editor window. To
open the editor window simply, type edit at the prompt and then
press return
>> edit
Saving the data
Retrieving the data
2.5 Command, Algorithm and Program
A command is an instruction to do a specific task
while an algorithm is a sequence of instructions for the solution
of a given problem in a finite number of steps.
A program is an implementation of an algorithm suitable for
execution by a computer.
Comment(%)
23 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

2.6 On-line help

MATLAB renders help facility from documentation on-line. To


use this facility you need to type help followed by the command
name at the prompt and then press return.
Example
>> help plus the comprehensive help commands available in the
MATLAB system are
I
I

24 / 26

helpdesk- displays a hypertext help browser in a new window


helpwin - Opens all m-file help degault topics. i.e. a MATLAB
help graphic user interface in a new window.

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

Thank You!

25 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

East African Pressure Level

26 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Introduction

East African Pressure Level

26 / 26

Gemechu Fanta

Introduction to Computing with MATLAB

Você também pode gostar