# 03 Types, type conversions and floating point arithmetic

AI悦创原创python 1v1留学生作业辅导剑桥大学大约 2 分钟...约 685 字

## # Exercise 03.1

EN

Compare the computed values of

$d_0 = a \cdot b + a \cdot c$

and

$d_1 = a \cdot (b + c)$

when $a = 100$, $b = 0.1$ and $c = 0.2$. Store $d_{0}$ in the variable d0 and $d_{1}$ in the variable d1.

Try checking for equality, e.g. print(d0 == d1).

a = ...
b = ...
c = ...

d0 = ...
print(d0)

d1 = ...
print(d1)

print(d0 == d1)

## tests ##
assert d0 == 30.0
assert d1 != 30.0
assert d0 != d1


## # Exercise 03.2

For the polynomial

\begin{align} f(x, y) &= (x + y)^{6} \\ &= x^6 + 6x^{5}y + 15x^{4}y^{2} + 20x^{3}y^{3} + 15x^{2}y^{4} + 6xy^{5} + y^{6} \end{align}

compute $f$ using: (i) the compact form $(x + y)^{6}$; and (ii) the expanded form for:

(a) $x = 10$ and $y = 10.1$

(b) $x = 10$ and $y = -10.1$

and compare the number of significant digits for which the answers are the same.
Store the answer for the compact version using the variable f0, and using the variable f1 for the expanded version.

For case (b), compare the computed and analytical solutions and consider the relative error.
Which approach would you recommend for computing this expression?

AI悦创·编程一对一

AI悦创·推出辅导班啦，包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」，全部都是一对一教学：一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然，还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线，随时响应！微信：Jiabcdefh

C++ 信息奥赛题解，长期更新！长期招收一对一中小学信息奥赛集训，莆田、厦门地区有机会线下上门，其他地区线上。微信：Jiabcdefh

• 0
• 0
• 0
• 0
• 0
• 0

• 按正序
• 按倒序
• 按热度