Sei sulla pagina 1di 9

University of Bahrain

College of Information Technology


Department of Computer Engineering

ITCE 380: Numerical Analysis


Experiment #1: Numbers in MATLAB

STUDENT’S NAME: Amna Azmat Raza Malik


STUDENT’S ID: 20161934
DATE OF SUBMISSION: 14 October 2018
AIM: The aim of this experiment is to get familiar with the MATLAB software
and how to make use of MATLAB to get the values of numbers in single and
double precision easily.
INTRODUCTION: MATLAB is a technical language to ease scientific
computations. The name is derived from matrix laboratory. It provides many of
the attributes of spreadsheets and programming languages. MATLAB is a case
sensitive language. MATLAB is a high-level programming language that has
been used extensively to solve complex engineering problems. The language
itself bears some similarities with ANSI C and FORTRAN
Integer Classes
MATLAB® has four signed and four unsigned integer classes. Signed types enable
you to work with negative integers as well as positive, but cannot represent as
wide a range of numbers as the unsigned types because one bit is used to designate
a positive or negative sign for the number. Unsigned types give you a wider range
of numbers, but these numbers can only be zero or positive.

Class Range of Values Conversion Function


Signed 8-bit integer -27 to 27-1 int8
Signed 16-bit integer -215 to 215-1 int16
31 31
Signed 32-bit integer -2 to 2 -1 int32
63 63
Signed 64-bit integer -2 to 2 -1 int64
Unsigned 8-bit integer 0 to 28-1 uint8
Unsigned 16-bit integer 0 to 216-1 uint16
32
Unsigned 32-bit integer 0 to 2 -1 uint32
64
Unsigned 64-bit integer 0 to 2 -1 uint64
MATLAB supports 1-, 2-, 4-, and 8-byte storage for integer data. You can save
memory and execution time for your programs if you use the smallest integer type
that accommodates your data. For example, you do not need a 32-bit integer to
store the value 100.
Here are the eight integer classes, the range of values you can store with each type,
and the MATLAB conversion function required to create that type:
Floating-Point Numbers
MATLAB® represents floating-point numbers in either double-precision or single-
precision format. The default is double precision, but you can make any number
single precision with a simple conversion function.
Double-Precision Floating Point
MATLAB constructs the double-precision (or double) data type according to IEEE®
Standard 754 for double precision. Any value stored as a double requires 64 bits
(see lecture notes).
Single-Precision Floating Point
MATLAB constructs the single-precision (or single) data type according to IEEE
Standard 754 for single precision. Any value stored as a single requires 32 bits (see
lecture notes).
Use double-precision to store values greater than approximately 3.4 x 1038 or less
than approximately -3.4 x 1038. For numbers that lie between these two limits, you
can use either double- or single-precision, but single requires less memory.

Procedure:
1) MATLAB was turned on.
2) The value of the irrational number π, was obtained by entering the following in
MATLAB:
pi
(the default format is the short, fixed-decimal format for floating-point notation, count the number
of digits)

3) Inorder to get more précised value the format was changed to long and the
following command was entered.
format long pi
4) In order to obtain the value of π in IEE754 double precision
the following command was entered.
format hex pi

5) The format of π was changed with (22/7) to rational, the following command
was entered:
format rat pi

6) To reset the output format to the default, format was entered.

7) π is a transcendental number, to increase the precision to 100 digits !,


the following operation was entered:
vpa(pi,100)

8) To find the largest floating IEEE 754 double precision number, realmax, was entered
and for the smallest, realmin was entered.
Realmin

For IEEE 754 single precision, we used realmax(‘single’) and realmin


(‘single’).
realmax

Realmin

9) eps was entered inorder to compare the answers with the previous one.
10) The result of following operations was obtained:
1/0

0/0

0^0

QUESTIONS AND ANSWERS:

1) Show and discuss all your results.


2) Use MATLAB or a calculator and calculate the relative accuracy of π value
(between single and double precision).
3) What are the largest and smallest numbers in hex for both single and double
precisions?
CONCLUSION: In this experiment we got familiar with the basic commands of
MATLAB and we were able to find out the numbers in single and double
precision.

Potrebbero piacerti anche