Introduction To Matlab: Bushra Fatima NED University of Engineering & Technology
Introduction To Matlab: Bushra Fatima NED University of Engineering & Technology
Bushra Fatima
NED University of Engineering & Technology
May 18, 2020
Outline – Lecture 02
• Display Formats
Textbook: A. Gilat, Matlab: An Introduction with Applications 6th Edition. John Wiley
& Sons, Incorporated, 2016. (Chapter 1: Introduction)
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 3 of 15
Addition: 3+2
Subtraction: 3-2
Multiplication: 3*2
Division: 3/2 or 2\3
Exponent: 3^2
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 4 of 15
Order of Precedence
Precedence Operation
First Parentheses, evaluated starting with the
innermost pair
Second Exponentiation
Third Multiplication and division with equal
precedence
Fourth Addition and subtraction with equal
precedence
Note:
If two or more operations have the same precedence, the
expression is executed from left to right.
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 5 of 15
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 6 of 15
Display formats
Command Description Example
>> 290/7
format short
upto 4 decimal digits ans =
(default)
41.4286
>> 290/7
ans =
format long upto 15 decimal digits
41.4285714285
71431
>> 290/7
format short e scientific notation with 4 decimal digits ans =
4.1429e+001
>> 290/7
ans =
format long e scientific notation with 15 decimal digits
4.14285714285
7143e+001
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 7 of 15
Display formats
Command Description Example
>> 290/7
format short g 5 s.g.f of floating digits ans =
41.429
>> 290/7
ans =
format long g 15 s.g.f of floating digits
41.4285714285
714
>> 290/7
format bank upto 2 decimal digits ans =
41.43
Eliminates empty lines to allow more lines with information
format compact
displayed on the screen.
format loose
Adds empty lines (opposite of compact).
(default) METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 8 of 15
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 9 of 15
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 10 of 15
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 11 of 15
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 12 of 15
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 13 of 15
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
ARITHMETIC | DISPLAY FORMATS | VARIABLES 15 of 15
Infinity:
1/0
inf + 3
Not-a-Number (NaN):
0/0
METU NCC