ex3: finish
This commit is contained in:
Binary file not shown.
@@ -23,16 +23,14 @@
|
||||
these are my solutions to the third exercise set of TMA4135.
|
||||
|
||||
there should be a python source code file attached to this deliverable.
|
||||
this file can be used to generate the images shown in problem 2.
|
||||
|
||||
this document was created using
|
||||
#link("https://typst.app/")[#text(blue.darken(5%))[typst]].
|
||||
|
||||
#v(42pt)
|
||||
#v(1fr)
|
||||
|
||||
#outline(title: none)
|
||||
|
||||
#v(42pt)
|
||||
|
||||
#pagebreak()
|
||||
|
||||
@@ -212,7 +210,7 @@ $
|
||||
|E_([a,b])^n [f]| <= (b-a)^3/(12n^2) max_(xi in [a,b]) |f''(xi)|
|
||||
$
|
||||
|
||||
=== first problem: $|E_([0,1])^n [exp]| <= 10^(-3)$
|
||||
*first problem:* $|E_([0,1])^n [exp]| <= 10^(-3)$
|
||||
|
||||
for $f(x) = e^x$, we have $f''(x) = e^x$.
|
||||
since $e^x$ is increasing, $max_(xi in [0,1]) |f''(xi)| = e$.
|
||||
@@ -225,14 +223,14 @@ solving: $n^2 >= e/(12 dot 10^(-3)) = 1000e/12$
|
||||
|
||||
therefore $n >= sqrt(1000e/12) approx 15.05$, so $n >= 16$.
|
||||
|
||||
=== second problem: $|E_([0,1])^n [ln]| <= 10^(-5)$
|
||||
*second problem:* $|E_([0,1])^n [ln]| <= 10^(-5)$
|
||||
|
||||
for $f(x) = ln(x)$, we have $f''(x) = -1/x^2$.
|
||||
since $|f''(x)| = 1/x^2 -> infinity$ as $x -> 0^+$,
|
||||
the function is not twice differentiable at $x = 0$.
|
||||
the trapezoidal rule error bound does not apply.
|
||||
|
||||
=== third problem: $|E_([1,2])^n [e^x/x]| <= 10^(-3)$
|
||||
*third problem:* $|E_([1,2])^n [e^x/x]| <= 10^(-3)$
|
||||
|
||||
for $f(x) = e^x/x$, using the quotient rule:
|
||||
$f''(x) = (e^x (x^2 - 2x + 2))/x^3$
|
||||
@@ -363,6 +361,94 @@ needed, making it more efficient than uniform refinement.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
= problem 2
|
||||
|
||||
== a)
|
||||
|
||||
to transform the quadrature rule from $[-1,1]$ to $(-3,3)$ we use
|
||||
$
|
||||
x = (b - a)/2 t + (b + a)/2 = 3 t
|
||||
$
|
||||
where $t in [-1,1]$, so $d x = 3 d t$. then
|
||||
|
||||
$
|
||||
integral_(-3)^3 e^x d x = integral_(-1)^1 e^(3t) dot 3 d t = 3 integral_(-1)^1 e^(3t) d t
|
||||
$
|
||||
|
||||
the gauß-legendre approximation is given by
|
||||
$
|
||||
G_h = 3 sum_(i=0)^3 w_i e^(3 x_i)
|
||||
$
|
||||
|
||||
so
|
||||
|
||||
#[
|
||||
#let x0 = -1 / 35 * calc.sqrt(525 + 70 * calc.sqrt(30))
|
||||
#let x1 = -1 / 35 * calc.sqrt(525 - 70 * calc.sqrt(30))
|
||||
#let x2 = 1 / 35 * calc.sqrt(525 - 70 * calc.sqrt(30))
|
||||
#let x3 = 1 / 35 * calc.sqrt(525 + 70 * calc.sqrt(30))
|
||||
|
||||
#let w0 = 1 / 36 * (18 - calc.sqrt(30))
|
||||
#let w1 = 1 / 36 * (18 + calc.sqrt(30))
|
||||
#let w2 = 1 / 36 * (18 + calc.sqrt(30))
|
||||
#let w3 = 1 / 36 * (18 - calc.sqrt(30))
|
||||
|
||||
$
|
||||
G_h & = 3(w_0 e^(3 x_0) + w_1 e^(3 x_1) + w_2 e^(3 x_2) + w_3 e^(3 x_3)) \
|
||||
& = 3(#(w0 * calc.exp(3 * x0) + w1 * calc.exp(3 * x1) + w2 * calc.exp(3 * x2) + w3 * calc.exp(3 * x3))) \
|
||||
& = #(3 * (w0 * calc.exp(3 * x0) + w1 * calc.exp(3 * x1) + w2 * calc.exp(3 * x2) + w3 * calc.exp(3 * x3)))
|
||||
$
|
||||
|
||||
wheras the exact value is $e^3 - e^(-3) = #(calc.exp(3) - calc.exp(-3))$.
|
||||
]
|
||||
|
||||
|
||||
|
||||
== b)
|
||||
|
||||
from the given error formula, each subinterval of length $h = (b-a)/m$ contributes error
|
||||
|
||||
$
|
||||
E_i prop h^(2n+1) = ((b-a)/m)^(2n+1)
|
||||
$
|
||||
|
||||
total error from m subintervals
|
||||
$
|
||||
E_m prop m dot ((b-a)/m)^(2n+1) = (b-a)^(2n+1)/m^(2n)
|
||||
$
|
||||
|
||||
we expect error to decrease when we subdivide the interval. more subintervals
|
||||
means more precision.
|
||||
|
||||
|
||||
|
||||
== c)
|
||||
|
||||
let $f(x) = x^8/8!$
|
||||
|
||||
we can see that $f^((2n))(x) = x^(8-2n)/(8-2n)!$ for $n > 0$ and $<= 8$ so
|
||||
$
|
||||
E_1 = (6^(2n+1) (n!)^4)/((2n+1)[(2n)!]^3) dot xi^(8-2n)/((8-2n)!)
|
||||
$
|
||||
|
||||
then sum the left and right errors to obtain
|
||||
$
|
||||
E_2 = (3^(2n+1) (n!)^4)/((2n+1)[(2n)!]^3) dot (xi_1^(8-2n) + xi_2^(8-2n))/((8-2n)!)
|
||||
$
|
||||
|
||||
which yields
|
||||
$
|
||||
E_2/E_1 = (xi_1^(8-2n) + xi_2^(8-2n))/(2^(2n+1) xi^(8-2n))
|
||||
$
|
||||
|
||||
we can see that increasing n makes it more accurate very fast, as the numerator
|
||||
grows smaller exponentially and the denominator bigger.
|
||||
|
||||
|
||||
|
||||
|
||||
= problem 3
|
||||
|
||||
== a)
|
||||
@@ -417,6 +503,7 @@ $
|
||||
$
|
||||
|
||||
|
||||
|
||||
== c)
|
||||
|
||||
let
|
||||
@@ -431,11 +518,72 @@ where $n - 1 = 2$ since $k = 0, 1, 2$.
|
||||
|
||||
computing the cardinal polynomials, we obtain
|
||||
$
|
||||
ell_0(x) & = (x - x_1) / (x_0 - x_1) dot (x - x_2) / (x_0 - x_2)
|
||||
// = (x^2 - x_1 x - x_2 x + x_1 x_2) / (x_0^2 - x_1 x_0 - x_2 x_0 + x_1 x_2)
|
||||
= (1 - 2 x) / sqrt(3/5) dot (x - 1/2 + 1/2 sqrt(3/5)) / sqrt(3/5) \
|
||||
& = (5 (x - 1/2 + 1/2 sqrt(3/5) - 2x^2 - x + x sqrt(3/5)))/3 \
|
||||
& = 5 / 3 (-2 x^2 + sqrt(3/5) x + 1/2 sqrt(3/5) - 1/2) \
|
||||
ell_1(x) & = (x - x_0) / (x_1 - x_0) dot (x - x_2) / (x_1 - x_2)
|
||||
= (2 x - 1 + sqrt(3/5))/(sqrt(3/5)) dot (2 x - 1 + sqrt(3/5)) / sqrt(3/5) \
|
||||
ell_0(x) & = (x - x_1) / (x_0 - x_1) dot (x - x_2) / (x_0 - x_2) \
|
||||
& = (x - 1/2) / (-1/2 sqrt(3/5)) dot (x - 1/2 - 1/2 sqrt(3/5)) / (-sqrt(3/5)) \
|
||||
& = 5/3 (-2x^2 + sqrt(3/5) x + 1/2 sqrt(3/5) - 1/2) \
|
||||
ell_1(x) & = (x - x_0) / (x_1 - x_0) dot (x - x_2) / (x_1 - x_2) \
|
||||
& = (x - 1/2 + 1/2 sqrt(3/5)) / (1/2 sqrt(3/5)) dot (x - 1/2 - 1/2 sqrt(3/5)) / (1/2 sqrt(3/5)) \
|
||||
& = 4/3 (x^2 - x + 1/10) \
|
||||
ell_2(x) & = (x - x_0) / (x_2 - x_0) dot (x - x_1) / (x_2 - x_1) \
|
||||
& = 5/3 (-2x^2 - sqrt(3/5) x + 1/2 sqrt(3/5) + 1/2)
|
||||
$
|
||||
|
||||
integrating to find the weights
|
||||
$
|
||||
w_0 & = integral_0^1 ell_0(x) dd(x) = 5/18 \
|
||||
w_1 & = integral_0^1 ell_1(x) dd(x) = 4/9 \
|
||||
w_2 & = integral_0^1 ell_2(x) dd(x) = 5/18
|
||||
$
|
||||
|
||||
by symmetry we have $w_0 = w_2$.
|
||||
|
||||
|
||||
== d)
|
||||
|
||||
the 3-point gauß-legendre quadrature rule for $[0,1]$ is
|
||||
$
|
||||
integral_0^1 f(x) dd(x) approx 5/18 f(x_0) + 4/9 f(1/2) + 5/18 f(x_2)
|
||||
$
|
||||
where $x_0 = 1/2 - 1/2 sqrt(3/5)$ and $x_2 = 1/2 + 1/2 sqrt(3/5)$.
|
||||
|
||||
to verify that the 3-point rule integrates $x^5$ exactly, we compute
|
||||
$
|
||||
integral_0^1 x^5 dd(x) = x^6/6 |_0^1 = 1/6
|
||||
$
|
||||
and using the symmetry property and binomial expansion for $x_0^5 + x_2^5$ where
|
||||
$x_0 = 1/2 - 1/2 sqrt(3/5)$ and $x_2 = 1/2 + 1/2 sqrt(3/5)$, we obtain
|
||||
|
||||
$
|
||||
5/18 (x_0^5 + x_2^5) + 4/9 dot 1/32 = 1/6
|
||||
$
|
||||
|
||||
#h(1fr) $qed$
|
||||
|
||||
|
||||
== e)
|
||||
|
||||
to show equivalence with the standard table, we transform from the reference interval $[-1, 1]$ to $[0, 1]$ using:
|
||||
$
|
||||
x = (t + 1)/2 quad "where" t in [-1, 1] "and" x in [0, 1]
|
||||
$
|
||||
|
||||
so
|
||||
$
|
||||
x_0 & = (-sqrt(15)/5 + 1)/2 = 1/2 - sqrt(15)/10 \
|
||||
x_1 & = (0 + 1)/2 = 1/2 \
|
||||
x_2 & = (sqrt(15)/5 + 1)/2 = 1/2 + sqrt(15)/10
|
||||
$
|
||||
|
||||
using the change of variables $x = (t+1)/2$, we have $dd(x) = 1/2 dd(t)$.
|
||||
so
|
||||
$
|
||||
w_0 & = 5/9 dot 1/2 = 5/18 \
|
||||
w_1 & = 8/9 dot 1/2 = 4/9 \
|
||||
w_2 & = 5/9 dot 1/2 = 5/18
|
||||
$
|
||||
|
||||
note that $sqrt(15)/10 = 1/2 sqrt(3/5)$ so the transformed rule matches exactly
|
||||
our derived 3-point gauß-legendre quadrature for $[0, 1]$, confirming that both
|
||||
approaches yield the same integration rule.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user