## Exercise 03.1

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)`. 


```python
# YOUR CODE HERE
raise NotImplementedError()
```


```python
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?

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


```python
x = 10.0
y = 10.1

# YOUR CODE HERE
raise NotImplementedError()
```


```python
import math
assert math.isclose(f0, 65944160.60120103, rel_tol=1e-10)
assert math.isclose(f1, 65944160.601201, rel_tol=1e-10)
```

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


```python
x = 10.0
y = -10.1

# YOUR CODE HERE
raise NotImplementedError()
```


```python
import math
assert math.isclose(f0, 1.0e-6, rel_tol=1e-10)
assert math.isclose(f1, 1.0e-6, rel_tol=1e-2)
```

## Exercise 03.3

Consider the expression

$$
f = \frac{1}{\sqrt{x^2 - 1} - x}
$$

When $x$ is very large, the denominator approaches zero, which can cause problems.

Try rephrasing the problem and eliminating the fraction by multiplying the numerator and denominator by $\sqrt{x^2 - 1} + x$ and evaluate the two versions of the expression when:

(a) $x = 1 \times 10^{7}$

(b) $x = 1 \times 10^{9}$ (You may get a Python error for this case. Why?)

#### (a) $x = 1 \times 10^{7}$


```python
# YOUR CODE HERE
raise NotImplementedError()
```

#### (b) $x = 1 \times 10^{9}$


```python
# YOUR CODE HERE
raise NotImplementedError()
```

5d6e8640e4c12cc895cca1590f8a4f4800307885
ipynb
Jupyter Notebook
Assignment/03 Exercises.ipynb
reddyprasade/PYTHON-BASIC-FOR-ALL
4fa4bf850f065e9ac1cea0365b93257e1f04e2cb
MIT
2019-06-28T05:11:17.000Z
2022-03-16T02:02:28.000Z
Assignment/03 Exercises.ipynb
chandhukogila/Python-Basic-For-All-3.x
f4105833759a271fa0777f3d6fb96db32bbfaaa4
MIT
2021-12-28T14:15:58.000Z
2021-12-28T14:16:02.000Z
Assignment/03 Exercises.ipynb
chandhukogila/Python-Basic-For-All-3.x
f4105833759a271fa0777f3d6fb96db32bbfaaa4
MIT
2019-07-07T03:20:33.000Z
2021-05-08T10:44:18.000Z
Qwen/Qwen-72B
1. YES
2. YES