找回密码
 注册
关于网站域名变更的通知
查看: 504|回复: 1
打印 上一主题 下一主题

介绍一下Matlab的浮点相对精度eps

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2019-12-18 11:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x

5 |, L; O1 Q/ s  i& p: s目录
. B2 |$ _, L3 `6 p5 o# U" R
( @- E4 C' y  M% c% u. {$ [- H% c5 t+ t5 O
eps
9 }% @6 R, U2 g: N9 E! [8 ~) r# Y4 V
       Syntax; k" R) W6 D- V$ K) W& H

7 Y: F2 _$ c) `- p' v; u       Description
3 G' I6 F) `0 i1 E) K7 F4 L" x( N0 w: z
              Accuracy in Double Precision
& [3 c* n2 s- R9 |/ j$ }2 a) d: v! a3 J
              Accuracy in Single Precision
2 d) h6 g1 P& ~  X' k/ X9 o7 D: }0 ?1 v

' d, z' q' m% R" c! {, geps
  h* \/ M) G9 qFloating-point relative accuracy- B) |2 l! ?: o

& e) e7 M/ z! ]$ p5 hSyntax
7 \: l# E( @6 P  L1 \1 Bd = eps
; P$ T$ w6 ~+ I% h3 d+ J0 U' O( m# \7 d
d = eps(x)
, f5 V- \# s1 H( f$ y
. N+ W; H" D% h& G  t# w4 v! G* r7 _d = eps(datatype)
! I* I! N/ y; J* [4 N
+ a* V6 J, L) U, bDescription
% R: t! Q$ U! @; @3 |5 `
& r$ U2 L, x6 Md = eps returns the distance from 1.0 to the next larger double-precision number, that is, .( b/ H1 g- i1 |# V+ [
0 `+ |. V- P  h% D/ r
d = eps返回从1.0到下一个更大的双精度数的距离,即。4 |6 o6 E% i: c% {% h$ d* E# h0 ~2 u

1 V( }/ N% T; q7 _d = eps(x), where x has data type single or double, returns the positive distance from abs(x) to the next larger floating-point number of the same precision as x. If x has typeduration, then eps(x) returns the next larger duration value. The command eps(1.0) is equivalent to eps.9 U, }# O( p3 k- m* W3 E" y

7 k5 \* M8 x0 C$ a: \  Q# @" J- Ud = eps(x),其中x具有数据类型single或double,返回从abs(x)到下一个与x相同精度的较大浮点数的正距离。 如果x具有typeduration,则eps(x)返回下一个更大的持续时间值。 命令eps(1.0)等同于eps。
% n7 P4 {' R  S) k
. k2 t6 q% D& O/ f* {: vd = eps(datatype) returns eps according to the data type specified by datatype, which can be either 'double' or 'single'. The syntax eps('double') (default) is equivalent to eps, and eps('single') is equivalent to eps(single(1.0)).
% ?9 I( |  j% U  d5 t8 g& v) h" w) @
d = eps(datatype)根据datatype指定的数据类型返回eps,数据类型可以是“double”或“single”。 语法eps('double')(默认)等同于eps,eps('single')等同于eps(single(1.0))。
( I" X; Y" S2 |, K) _$ k
+ x1 j* P' B' k1 A0 z* G& P2 c1 z
Accuracy in Double Precision
9 o0 o5 d, D9 q8 i, f* \; c, S* p# ?7 V8 G4 U1 `9 q

' s2 l: L8 T; c, x  j! t. n  g
  • clc
  • clear
  • close all
  • % Display the distance from 1.0 to the next largest double-precision number.
  • d = eps
  • % d = 2.2204e-16
  • % eps is equivalent to eps(1.0) and eps('double').
  • % Compute log2(eps).
  • d = log2(eps)
  • % d = -52
  • % In base 2, eps is equal to 2^-52.
  • %
  • % Find the distance from 10.0 to the next largest double-precision number.
  • d = eps(10.0)
  • % d = 1.7764e-159 F" g! T+ D  N$ v% V5 E
   
4 @& H2 E9 w( n) S, t+ t1 w
* a; a6 h+ v! w. i, n: S( K结果如下:
1 c( ?' K# j/ K( f; {# G% p8 ]  k; L+ R2 d( U, |
d =
: c! ?$ ?; U" ^9 K7 Z/ r# {) O- W& {- P. @8 p
   2.2204e-16
: N# z. ~6 _% k& ]$ r+ ~9 G
3 F  c- p1 H7 p+ K) Ld =
- c3 l7 t- V' v9 V, b: |, Q
8 u% [9 f. B7 l/ F" J7 w4 }( Q: n   -52- H+ Q8 z' b; s
3 U$ j4 b2 S" i& p
d =
7 X2 U$ U- K6 \: I- N( Y# `8 y4 M1 J; N- i2 Z' H4 M
   1.7764e-15
% }1 H. ^6 c6 Y( g( j4 l0 }" i$ P+ A, l0 |& t: n0 w" g0 u

, k* t2 `5 G( s$ g' G9 LAccuracy in Single Precision
6 [6 ~& w. ?9 Q0 S6 u: }2 H3 c3 y7 k" R5 v
  • clc
  • clear
  • close all
  • % Display the distance from 1.0 to the next largest single-precision number.
  • d = eps('single')
  • % d = single
  • %     1.1921e-07
  • % eps('single') is equivalent to eps(single(1.0)).
  • % Compute log2(eps('single')).
  • d = log2(eps('single'))
  • % d = single
  • %     -23
  • % In base 2, single-precision eps is equal to 2^-23.
  • % Find the distance from the single-precision representation of 10.0 to the next largest single-precision number.
  • d = eps(single(10.0))
  • % d = single
  • %     9.5367e-07  j$ o- M; q9 D2 U/ r/ X; p
     
2 n( d5 W5 g+ `5 t. n+ P/ a6 s$ ?) m- Z8 ]$ `
结果如下:
* e- R- C% b+ i  \1 r" {& w( T3 s) i1 e0 v3 A( Y
d =
/ @$ t8 e2 f1 ^  ]2 }' f" g9 |. J) S6 n: J" B
  single
2 G& j$ x9 h" S5 ^8 P4 i  {
! A4 T0 Z5 _7 S3 x6 ~8 W  1.1921e-07
0 N; p: Z" B# g+ }" O% S3 W8 j5 e1 @0 q
d =3 [$ q# k- |3 g" D+ D# [1 `. V
( C' O$ E0 Z3 a% S& F
  single6 X1 R; Z! m( @) j1 S$ l5 A$ {* K8 q
  ?% V0 Y, m0 [
   -23
0 D. I: }' t6 e0 {& Q6 D
3 V5 R! l. u, T# K  \d =9 M# S4 G1 H& }: K
) [/ V/ I; E- R6 u! b6 o. D
  single2 X& c  ^0 b6 r0 s$ C; T
! P$ i0 b. w3 A0 W" e0 {3 R
  9.5367e-07# |* R1 U" E% ]7 s
" j- ]8 f' a, V- F9 @$ E; t2 R
, j  i9 q" v: A# T; c" _% g" J
, R. H$ R5 ^  C/ ~
2 p" }; g9 e# E2 U1 l
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-7-19 12:44 , Processed in 0.140625 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表