Skip to content

Commit a503a39

Browse files
Smit-createmmcky
andauthored
Fix sympy imports and exercise (#367)
Co-authored-by: mmcky <[email protected]>
1 parent 177218b commit a503a39

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

lectures/complex_and_trig.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ We'll need the following imports:
102102
import matplotlib.pyplot as plt
103103
plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
104104
import numpy as np
105-
from sympy import *
105+
from sympy import (Symbol, symbols, Eq, nsolve, sqrt, cos, sin, simplify,
106+
init_printing, integrate)
106107
```
107108

108109
### An Example
@@ -491,11 +492,38 @@ integrate(cos(ω) * sin(ω), (ω, -π, π))
491492
We invite the reader to verify analytically and with the `sympy` package the following two equalities:
492493
493494
$$
494-
\int_{-\pi}^{\pi} \cos (\omega)^2 \, d\omega = \frac{\pi}{2}
495+
\int_{-\pi}^{\pi} \cos (\omega)^2 \, d\omega = \pi
495496
$$
496497
497498
$$
498-
\int_{-\pi}^{\pi} \sin (\omega)^2 \, d\omega = \frac{\pi}{2}
499+
\int_{-\pi}^{\pi} \sin (\omega)^2 \, d\omega = \pi
499500
$$
501+
```
502+
503+
```{solution-start} complex_ex1
504+
:class: dropdown
505+
```
506+
507+
Let's import symbolic $\pi$ from `sympy`
508+
509+
```{code-cell} ipython3
510+
# Import symbolic π from sympy
511+
from sympy import pi
512+
```
513+
514+
```{code-cell} ipython3
515+
print('The analytical solution for the integral of cos(ω)**2 \
516+
from -π to π is:')
517+
518+
integrate(cos(ω)**2, (ω, -pi, pi))
519+
```
520+
521+
```{code-cell} ipython3
522+
print('The analytical solution for the integral of sin(ω)**2 \
523+
from -π to π is:')
524+
525+
integrate(sin(ω)**2, (ω, -pi, pi))
526+
```
500527

528+
```{solution-end}
501529
```

0 commit comments

Comments
 (0)