Numerical accuracy in Matlab

1. There are three kinds of arithmetic precision in Matlab, they are numerical algorithm, symbolic algorithm and controllable precision algorithm. They are introduced as follows:

(1) Numerical algorithm takes each number as 16 bits, and the calculation is performed by floating point operation, which is the fastest algorithm.

(2) Symbolic algorithm converts each number into a symbolic quantity, and the operation is carried out according to rational quantity calculation.

(3) The controllable precision algorithm is between the above two algorithms, and it can make the calculation under controllable precision.

2. The data display format of Matlab, the list is as follows:

 

 Table Matlab data display format command

Order

significance

Example ( )

format short

Short format mode, display 5-digit fixed-point decimal number

3.1416

format long

Long format, display 15-bit fixed-point decimal number

3.141592653589793

format short e

Optimized short format display, 5 digits plus exponent

3.1416e+000

format long e

Optimal format, 15 digits plus exponent

3.141592653589793e+000

format short g

5-bit fixed-point or floating-point format

3.1416

format long g

For double precision, display 15-bit fixed-point or floating-point format, for single-precision, display 7-bit fixed-point or floating-point format

3.14159265358979

format short eng

At least 5 digits plus 3 digits for exponent

3.1416e+000

format long eng

16 bits plus at least 3 bits of exponent

3.1415926358979e+000

format hex

hex format

400921fb54442d18

format bank

Bank format. Fixed format by yuan, angle, minute (with two decimal places)

3.14

format +

+ format, with +, - and space for positive, negative and zero elements in

+

format

The default is the default short format, the same as format short

3.1416

format rat

Fractional format form. Approximate display data with rational numbers

355/113

format loose

Loose format. Blank lines between data

 

format compact

Compact format. No blank lines between data

 

vpa(date,n)

Display data date with n significant digits

vpa(pi,5)= 3.1416

 

The format does not affect how matlab calculates and stores the value of the variable. Calculations on floating point variables, i.e. single or double precision, are performed with the appropriate floating point precision, regardless of how the variable is displayed. Use integer for integer variables Type data. Integer variables are always displayed with appropriate data bits according to different classes.

3. Matlab special variables

ans: reaction to recent input

computer: the current computer type

eps: floating point precision

flops: counts the number of floating-point operations, no longer commonly used

i: imaginary unit

inf: infinity

inputname: input parameter name

j: imaginary unit

nan: non-numeric

nargin: the number of input parameters

nargout: number of output arguments (user-defined function)

pi: pi

realmax: maximum number of positive floating points

realmin: minimum number of positive floating points

varargin  

varargout: returns the number of parameters (matlab function)

cputime: CPU working time

 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325576059&siteId=291194637