Skip to content

Commit

Permalink
finish numerical integration
Browse files Browse the repository at this point in the history
  • Loading branch information
CaveNightingale committed May 6, 2024
1 parent 1a11c83 commit 9f6aa0d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/lib/component/content/Graph.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
childList: true,
subtree: true,
});
new ResizeObserver(() => this.recompile()).observe(this);
}
get _directed() {
Expand All @@ -66,7 +65,7 @@
}
get _width() {
return Math.min(+this.getAttribute("width"), this.clientWidth);
return +this.getAttribute("width");
}
recompile() {
Expand Down
3 changes: 1 addition & 2 deletions src/routes/note/+page.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# To-do list

- Network flow
- Dirichlet convolution
- Numerical integration (Romberg / Lobatto)
- Dirichlet convolution
3 changes: 2 additions & 1 deletion src/routes/note/network-flow/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ $'fn{bfs}(s, t, vertices)$ [
$u.level = -1$
]
$q = {s}$
$s.level = -1$
$s.level = 0$
$'fn{QUQUE-PUSH}(q, s)$
while $'neg 'fn{QUQUE-EMPTY}(q)$ [
$u = 'fn{QUQUE-POP}(q)$
for $e$ in $u.edges$ [
Expand Down
68 changes: 68 additions & 0 deletions src/routes/note/numerical-integration/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,71 @@ Lobatto's idea is use $a$, $b$ and the roots of $P'_{n-2}(x)$ as the points $x_i

In this way, it uses the end points as information.

Personally speaking, I don't think this is a useful property. I don't see cases where we are forced to use the end points. And though my teacher uses tons of slides on this topic, it's not on the textbook or in the exam anyway. Thus I don't want to spend time on this.

## Romberg Integration

### Extrapolation

Suppose we have a formula to approximate $Q$.

$$
Q = F_n(h) + Kh^n + O(h^{n+1})
$$

where $h$ is a small number, and $K$ is a constant.

We cut $h$ into half, and get

$$
Q = F_n(\dfrac{h}{2}) + K\dfrac{h^n}{2^n} + O(h^{n+1})
$$

Then

$$
F_{n + 1}(h)\\
= \dfrac{2^n F_n(\dfrac{h}{2}) - F_n(h)}{2^n - 1}\\
= \dfrac{2^n (Q - K\dfrac{h^n}{2^n} - O(h^{n+1})) - (Q - Kh^n - O(h^{n+1}))}{2^n - 1}\\
= \dfrac{2^n Q - Kh^n - O(h^{n+1}) - Q + Kh^n + O(h^{n+1})}{2^n - 1}\\
= \dfrac{(2^n - 1)Q + O(h^{n+1})}{2^n - 1}\\
= Q + O(h^{n+1})
$$

This is called **extrapolation**.

### Romberg Integration

Supposse the function $f$ is infinitely differentiable.

We can apply the extrapolation to the Trapezoidal Rule.

Investigate the error of Trapezoidal Rule.

$$
\int_a^b f(x) dx = \dfrac{h}{2}(f(a) + f(b) + 2\sum_{i=1}^{n-1} f(a + ih)) + c_2h^2 + c_4h^4 + c_6h^6 + \cdots\\
$$

We found that $c_2, c_4, c_6, ...$ depend only on the high order derivatives of $f$, not $h$.

Then we can apply the extrapolation to the Trapezoidal Rule.

We cut the $h$ into half each time, and get $h_n = \dfrac{b - a}{2^n}$.

Then we obtained a sequence of second order approximations. Let them be $R_{1, 1}, R_{2, 1}, R_{3, 1}, \cdots$.

$$
R_{n, 2} = \dfrac{4R_{n, 1} - R_{n-1, 1}}{4 - 1}
$$

This cancel out the $h^2$ term, and gives $4$-th order approximation.

We can apply extrapolation multiple times. Generally, we get $2n$-th order approximation by the sequence of $2(n-1)$-th order approximations.
thought
$$
R_{n, m} = \dfrac{4^m R_{n, m-1} - R_{n-1, m-1}}{4^m - 1}
$$

Notice that the offset of the sequence increased by $1$ and the length of the sequence decreased by $1$ each time.

Finally when we get a sequence of single element $R_{n, n}$, we've got the $2n$-th order approximation.

0 comments on commit 9f6aa0d

Please sign in to comment.