round-off and truncation error(舍入和截断误差)

# round-off and truncation error
# 舍入和截断误差

1. Round-off errors are due to approximate representation of floating-point number

from math import pi
print(pi)
3.141592653589793

π \pi π=3.141592653589793238462643…

2. subtractive cancellation

x = 1 x=1 x=1
y = 1 + 1 0 − 15 2 y=1+10^{-15}\sqrt{2} y=1+10152

from math import sqrt
x = 1.0
y = 1.0 + 1e-15 * sqrt(2)
dt = 1e-15 * sqrt(2)
dn = y - x
print("dt = ", dt)
print("dn = ", dn)
print("Relative error: ", (dt - dn) / dt)
dt =  1.4142135623730953e-15
dn =  1.3322676295501878e-15
Relative error:  0.05794452478973511

similar accumulation of round-off in addition(large number + small number).

3. Truncation Errors

Truncation errors are created by truncating the math.

Example: MacLaurin Series for exponential function
e x = ∑ n = 0 ∞ x n n ! e^x=\sum_{n=0}^{\infty}\frac{x^n}{n!} ex=n=0n!xn

Now, we only use three terms
e x = ∑ n = 0 ∞ x n n ! ≈ 1 + x + x 2 2 ! e^x=\sum_{n=0}^{\infty}\frac{x^n}{n!}\approx 1 + x + \frac{x^2}{2!} ex=n=0n!xn1+x+2!x2

4. Numerical Differentiation and numerical errors

definition of true derivative
在这里插入图片描述

f ′ ( x ) = lim ⁡ d x → 0 f ( x + d x ) − f ( x ) d x f^{'}(x)=\lim_{dx\rightarrow 0}\frac{f(x+dx)-f(x)}{dx} f(x)=dx0limdxf(x+dx)f(x)

approximation of derivative(numerical derivative)
在这里插入图片描述

f ′ ( x i ) = f ( x i + 1 ) − f ( x i ) x i

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值