Data Types and Display Accuracy in MATLAB

Source: Internet
Author: User

; ========================================================== =

> Help class
Class return Class Name of object.
S = Class (OBJ) returns the name of the class of object obj.

Possibilities are:
Double -- Double Precision Floating Point Number Array
(This is the traditional MATLAB matrix or array)
Single -- single precision Floating Point Number Array
Logical -- logical array
Char -- character array
Cell -- CELL ARRAY
Struct -- structure array
Function_handle -- function handle
Int8 -- 8-bit signed integer Array
Uint8 -- 8-bit unsigned integer Array
Int16 -- 16-bit signed integer Array
Uint16 -- 16-bit unsigned integer Array
Int32 -- 32-bit signed integer Array
Uint32 -- 32-bit unsigned integer Array
Int64 -- 64-bit signed integer Array
Uint64 -- 64-bit unsigned integer Array
<Class_name> -- MATLAB class name for Matlab objects
<Java_class> -- Java class name for Java objects
 
% Example 1: Obtain the name of the class of value pi
Name = Class (PI );
 
% Example 2: obtain the full name of a package-based Java class
Import java. Lang .*;
OBJ = string ('mystring ');
Class (OBJ)
 
For classes created without a classdef Statement (pre-MATLAB version
7.6 syntax), Class invoked within a constructor method creates
Object of Type 'class _ name'. constructor methods are functions saved
In a file named <class_name>. M and placed in a directory named
@ <Class_name>. Note that 'class _ name' must be the second argument
Class. Uses of class for this purpose are shown below.
 
O = Class (S, 'class _ name') creates an object of class 'class _ name'
From the structure S.
 
O = Class (S, 'class _ name', parent1, parent2,...) also inherits
Methods and fields of the parent objects parent1, parent2 ,...
 
O = Class (struct ([]), 'class _ name', parent1, parent2,...), specifying
An empty structure S, creates an object that inherits the methods and
Fields from one or more parent classes, but does not have any
Additional fields beyond those inherited from the parents.
 
See also Isa, superiorto, inferiorto, classdef, struct.

================================================

> Help format
Format set output format.
Format with no inputs sets the output format to the default appropriate
For the class of the variable. For float variables, the default is
Format short.
 
Format does not affect how MATLAB computations are done. Computations
On Float variables, namely single or double, are done in appropriate
Floating Point precision, no matter how those variables are displayed.
Computations on integer variables are done natively in integer. Integer
Variables are always displayed to the appropriate number of digits
The class, for example, 3 digits to display the int8 range-:127.
Format short and long do not affect the display of integer variables.
 
Format may be used to switch between different output display formats
Of all float variables as follows:
Format short scaled fixed point format with 5 digits.
Format long scaled fixed point format with 15 digits for double
And 7 digits for single.
Format shorte floating point format with 5 digits.
Format longe floating point format with 15 digits for double and
7 digits for single.
Format shortg best of fixed or floating point format with 5
Digits.
Format longg best of fixed or floating point format with 15
Digits for double and 7 digits for single.
Format shorteng engineering format that has at least 5 digits
And a power that is a multiple of three
Format longeng engineering format that has exactly 16 Significant
Digits and a power that is a multiple of three.
 
Format may be used to switch between different output display formats
Of all numeric variables as follows:
Format hex hexadecimal format.
Format + the symbols +,-And blank are printed
For positive, negative and zero elements.
Imaginary parts are ignored.
Format bank fixed format for dollars and cents.
Format rat Approximation by ratio of small integers. Numbers
With a large numerator or large denominator are
Replaced *.
 
Format may be used to affect the spacing in the display of all
Variables as follows:
Format compact suppresses extra line-feeds.
Format loose puts the extra line-feeds back in.
 
Example:
Format short, PI, single (PI)
Displays both double and single PI with 5 digits as 3.1416 while
Format long, PI, single (PI)
Displays PI as 3.141592653589793 and single (PI) as 3.1415927.
 
Format, intmax ('int64'), realmax
Shows these values as 18446744073709551615 and 1.7977e + 308 while
Format hex, intmax ('int64'), realmax
Shows them as ffffffffffffff and 7 fefffffffffffffff respectively.
The hex display corresponds to the internal representation of the value
And is not the same as the hexadecimal notation in the C Programming
Language.
 
See also disp, display, isnumeric, isfloat, isinteger.
; ========================================================== =

> Help VPA
VPA variable precision arithmetic.
R = VPA (s) numerically evaluates each element of the double Matrix
S Using Variable Precision Floating Point Arithmetic with D decimal
Digit accuracy, where D is the current setting of digits.
The resulting R is a sym.

VPA (S, d) uses D digits, instead of the current setting of digits.
D is an integer or the sym representation of a number.
 
It is important to avoid the evaluation of an expression using double
Precision Floating Point Arithmetic before it is passed to VPA.
For example,
Phi = VPA (1 + SQRT (5)/2)
First computes a 16-digit approximation to the golden ratio, then
Converts that approximation to one with D digits, where D is the current
Setting of digits. To get full precision, use unevaluated string or
Symbolic arguments,
Phi = VPA ('(1 + SQRT (5)/2 ')
Or
S = Sym ('sqrt (5 )')
Phi = VPA (1 + S)/2 );
 
Additional examples:
VPA (PI, 780) shows six consecutive 9's near digit 770 in
Decimal expansion of pi.
 
VPA (hilb (2), 5) returns
 
[1.,. 50000]
[. 50000,. 33333]
 
See also double, digits.

Overloaded methods:
Sym/VPA

Reference page in help Browser
Doc VPA

VPA variable precision arithmetic.
R = VPA (s) numerically evaluates each element of S Using Variable
Precision Floating Point Arithmetic with D decimal digit accuracy,
Where D is the current setting of digits. R is a sym.
 
VPA (S, d) uses D digits, instead of the current setting of digits.
D is an integer or the sym representation of a number.
 
Examples:
Phi = Sym ('(1 + SQRT (5)/2'); % Phi is the "golden ratio ".
VPA (PHI, 75) is a string containing 75 digits of Phi.
 
VPA (Sym (PI), 1919) is a screen full of pi.
VPA (Sym ('exp (pI * SQRT (163) '), 36) shows an "almost integer ".
 
VPA (Sym (hilb (2), 5) returns
[1.,. 50000]
[. 50000,. 33333]
 
See also double, digits.

============================================

The minimum real number that MATLAB can represent is 2 ^ (-1074), and any real number whose absolute value is less than 2 ^ (-1074), Matlab treats it as 0.

> X = 2 ^ (-1074)

X = 4.9407e-324

> X = 2 ^ (-1075)

X = 0

> X = 0

Ans = 1

 

The default data type in MATLAB is double precision.

> STR = '/n/T % G to % G/n/T % G to % G ';
> Sprintf (STR,-realmax,-realmin, realmin, realmax)

Ans =

-1.79769e + 308 to-2.22507e-308%-2 ^ 1024 ~ -2 ^ (-1, 1022)
2.22507e-308 to 1.79769e + 308% 2 ^ (-1022 )~ 2 ^ 1024

 

MATLAB has a built-in constant EPS with a value of 2.2204*10 ^ (-16). It can be used as a comparison object for whether the real number is equal to 0.

> Help realmax
Realmax largest Positive floating point number.
X = realmax is the largest Double Precision Floating Point Number
Representable on this computer. Anything larger overflows.
 
Realmax ('double') is the same as realmax with no arguments.
 
Realmax ('single ') is the largest single precision Floating Point Number
Representable on this computer. Anything larger overflows to single (INF ).
 
See also EPS, realmin, intmax.

 

> Help EPS
EPS spacing of floating point numbers.
D = EPS (x), is the positive distance from ABS (X) to the next larger in
Magn?floating Point Number of the same precision as X.
X may be either double precision or single precision.
For all X, EPS (X) is equal to EPS (ABS (x )).
 
EPS, with no arguments, is the distance from 1.0 to the next larger double
Precision number, that is EPS with no arguments returns 2 ^ (-52 ).
 
EPS ('double') is the same as EPS, or EPS (1.0 ).
EPS ('single ') is the same as EPS (single (1.0), or single (2 ^-23 ).
 
Cannot t for numbers whose absolute value is smaller than realmin,
If 2 ^ e <= ABS (x) <2 ^ (E + 1), then
EPS (x) returns 2 ^ (E-23) If Isa (x, 'single ')
EPS (x) returns 2 ^ (E-52) If Isa (x, 'double ')
 
For all X of class double such that ABS (x) <= realmin, EPS (X)
Returns 2 ^ (-1074). Similarly, for all X of class single such that
ABS (x) <= realmin ('single '), EPS (x) returns 2 ^ (-149 ).
 
Replace expressions of the form
If y <EPS * ABS (X)
With
If y <EPS (X)
 
Example return values from calling EPS with varous inputs are
Presented in the table below:
 
Expression Return Value
========================================================== ===
EPS (1/2) 2 ^ (-53)
EPS (1) 2 ^ (-52)
EPS (2) 2 ^ (-51)
EPS (realmax) 2 ^ 971
EPS (0) 2 ^ (-1074)
EPS (realmin/2) 2 ^ (-1074)
EPS (realmin/16) 2 ^ (-1074)
EPS (INF) Nan
EPS (NAN) Nan
-------------------------------------------
EPS (single (1/2) 2 ^ (-24)
EPS (single (1) 2 ^ (-23)
EPS (single (2) 2 ^ (-22)
EPS (realmax ('single ') 2 ^ 104
EPS (single (0) 2 ^ (-149)
EPS (realmin ('single ')/2) 2 ^ (-149)
EPS (realmin ('single ')/16) 2 ^ (-149)
EPS (single (INF) single (NAN)
EPS (single (NAN)
 
See also realmax, realmin.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.