Skip to content

Commit 5cba3f1

Browse files
committed
Update notes
1 parent bd9fb14 commit 5cba3f1

File tree

7 files changed

+180
-155
lines changed

7 files changed

+180
-155
lines changed

leastsquare.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ Since $F(\theta)$ is even, the sine terms vanish, and this is also the full Four
710710

711711
---
712712

713-
Now if $f(x)$ is piecewise continuous, so is $F(\theta)$, and we know that
713+
Now if $f(x)$ is piecewise continuous, so is $F(\theta)$, and we know from [](#thm:fdecay) that
714714

715715
$$
716716
|a_j| = \order{\frac{1}{j}}, \qquad j \to \infty
@@ -720,7 +720,7 @@ In this case, we have $\norm{f - C_n}_2 \to 0$.
720720

721721
---
722722

723-
If $f \in \cts^{\nu-1}[-1,1]$ for some $\nu \ge 1$ and $f^{(\nu)}$ is piecewise continuous, then $F \in \cts^{\nu-1}_p[-\pi,\pi]$ and $F^{(\nu)}$ is piecewise continuous. This means that
723+
If $f \in \cts^{\nu-1}[-1,1]$ for some $\nu \ge 1$ and $f^{(\nu)}$ is piecewise continuous, then $F \in \cts^{\nu-1}_p[-\pi,\pi]$ and $F^{(\nu)}$ is piecewise continuous. From [](#thm:fdecay), this means that
724724

725725
$$
726726
|a_j| = \order{\frac{1}{j^{\nu+1}}}, \qquad j \to \infty

myst.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ project:
6060
- file: aquad.md
6161
- file: ode.md
6262
children:
63-
- file: ode/euler0.md
64-
- file: ode/euler1.md
63+
- file: ode/euler.md
6564
- file: ode/trapezoid1.md
66-
- file: ode/multistep_instability.md
65+
- file: ode/multistep.md
6766
- file: ode/fe_be_stability.md
6867
- file: ode/euler2.md
6968
- file: ode/ode_stability.md

newton_cotes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,5 @@ print("sum(w) = ", sum(w))
232232
print("sum(|w|) = ", sum(abs(w)))
233233
```
234234

235-
Because the weights are large in size, there is also more roundoff error when we add them, the sum is not exactly one.
235+
Because the weights are large in size and take both signs, there is also more roundoff error when we add them, and the sum is not exactly one. This error increases as we use more points.
236236
:::

ode/euler1.md renamed to ode/euler.md

Lines changed: 94 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,98 @@
11
---
2-
jupytext:
3-
text_representation:
4-
extension: .md
5-
format_name: myst
6-
format_version: 0.13
7-
jupytext_version: 1.16.7
2+
exports:
3+
- format: pdf
84
kernelspec:
9-
display_name: Python 3
5+
display_name: Python 3 (ipykernel)
106
language: python
117
name: python3
8+
numbering:
9+
code: false
10+
equation: true
11+
title: true
12+
headings: true
1213
---
1314

14-
# ODE using forward Euler
15+
# Forward Euler
16+
17+
```{include} ../math.md
18+
```
19+
20+
```{code-cell}
21+
import numpy as np
22+
from matplotlib import pyplot as plt
23+
```
24+
25+
:::{prf:example}
26+
Consider the ODE problem
27+
28+
\begin{gather}
29+
y' = y, \qquad t \ge 0 \\
30+
y(0) = 1
31+
\end{gather}
32+
33+
whose exact solution is
34+
35+
$$
36+
y(t) = \exp(t)
37+
$$
38+
39+
Right hand side function
40+
41+
```{code-cell}
42+
def f(t,y):
43+
return y
44+
```
45+
46+
Exact solution
47+
48+
```{code-cell}
49+
def yexact(t):
50+
return np.exp(t)
51+
```
52+
53+
This implements Euler method
54+
55+
$$
56+
y_n = y_{n-1} + h f(t_{n-1},y_{n-1})
57+
$$
58+
59+
```{code-cell}
60+
def euler(t0,T,y0,h):
61+
N = int((T-t0)/h)
62+
y = np.zeros(N)
63+
t = np.zeros(N)
64+
y[0] = y0
65+
t[0] = t0
66+
for n in range(1,N):
67+
y[n] = y[n-1] + h*f(t[n-1],y[n-1])
68+
t[n] = t[n-1] + h
69+
return t, y
70+
```
71+
72+
```{code-cell}
73+
t0,y0,T = 0.0,1.0,5.0
74+
75+
te = np.linspace(t0,T,100)
76+
ye = yexact(te)
77+
plt.plot(te,ye,'--',label='Exact')
78+
79+
H = [0.2,0.1,0.05]
80+
81+
for h in H:
82+
t,y = euler(t0,T,y0,h)
83+
plt.plot(t,y,label="h="+str(h))
84+
85+
plt.legend(loc=2)
86+
plt.xlabel('t')
87+
plt.ylabel('y')
88+
plt.grid(True);
89+
```
90+
:::
1591

1692
+++
1793

18-
Conside the ODE
94+
:::{prf:example}
95+
Consider the ODE
1996

2097
$$
2198
y' = -y + 2 \exp(-t) \cos(2t)
@@ -33,21 +110,16 @@ $$
33110
y(t) = \exp(-t) \sin(2t)
34111
$$
35112

36-
```{code-cell} ipython3
37-
import numpy as np
38-
from matplotlib import pyplot as plt
39-
```
40-
41113
Right hand side function
42114

43-
```{code-cell} ipython3
115+
```{code-cell}
44116
def f(t,y):
45117
return -y + 2.0*np.exp(-t)*np.cos(2.0*t)
46118
```
47119

48120
Exact solution
49121

50-
```{code-cell} ipython3
122+
```{code-cell}
51123
def yexact(t):
52124
return np.exp(-t)*np.sin(2.0*t)
53125
```
@@ -57,7 +129,7 @@ $$
57129
y_n = y_{n-1} + h f(t_{n-1},y_{n-1})
58130
$$
59131

60-
```{code-cell} ipython3
132+
```{code-cell}
61133
def euler(t0,T,y0,h):
62134
N = int((T-t0)/h)
63135
y = np.zeros(N)
@@ -70,9 +142,9 @@ def euler(t0,T,y0,h):
70142
return t, y
71143
```
72144

73-
## Solve for a given h
145+
**Solve for a given h**
74146

75-
```{code-cell} ipython3
147+
```{code-cell}
76148
t0,y0 = 0.0,0.0
77149
T = 10.0
78150
h = 1.0/20.0
@@ -87,13 +159,11 @@ plt.grid(True)
87159
plt.title('Step size = ' + str(h));
88160
```
89161

90-
## Solve for several h
91-
92-
+++
162+
**Solve for several h**
93163

94164
Study the effect of decreasing step size. The error is plotted in log scale.
95165

96-
```{code-cell} ipython3
166+
```{code-cell}
97167
hh = 0.1/2.0**np.arange(5)
98168
err= np.zeros(len(hh))
99169
for (i,h) in enumerate(hh):
@@ -115,3 +185,4 @@ plt.loglog(hh,err,'o-')
115185
plt.xlabel('h')
116186
plt.ylabel('Error norm');
117187
```
188+
:::

ode/euler0.md

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)