Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sympy imports and exercise #367

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions lectures/complex_and_trig.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ We'll need the following imports:
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
import numpy as np
from sympy import *
from sympy import (Symbol, symbols, Eq, nsolve, sqrt, cos, sin, simplify,
init_printing, integrate)
```

### An Example
Expand Down Expand Up @@ -491,11 +492,38 @@ integrate(cos(ω) * sin(ω), (ω, -π, π))
We invite the reader to verify analytically and with the `sympy` package the following two equalities:

$$
\int_{-\pi}^{\pi} \cos (\omega)^2 \, d\omega = \frac{\pi}{2}
\int_{-\pi}^{\pi} \cos (\omega)^2 \, d\omega = \pi
$$

$$
\int_{-\pi}^{\pi} \sin (\omega)^2 \, d\omega = \frac{\pi}{2}
\int_{-\pi}^{\pi} \sin (\omega)^2 \, d\omega = \pi
$$
```

```{solution-start} complex_ex1
:class: dropdown
```

Let's import symbolic $\pi$ from `sympy`

```{code-cell} ipython3
# Import symbolic π from sympy
from sympy import pi
```

```{code-cell} ipython3
print('The analytical solution for the integral of cos(ω)**2 \
from -π to π is:')

integrate(cos(ω)**2, (ω, -pi, pi))
```

```{code-cell} ipython3
print('The analytical solution for the integral of sin(ω)**2 \
from -π to π is:')

integrate(sin(ω)**2, (ω, -pi, pi))
```

```{solution-end}
```
Loading