Files
TMA4135/exercise3/exercise3.typ
2025-09-11 14:09:32 +02:00

200 lines
5.2 KiB
Typst

#import "@preview/cetz:0.3.2";
#import "@preview/cetz-plot:0.1.1": plot
#import "@preview/physica:0.9.4": *
#import "@preview/plotsy-3d:0.1.0": plot-3d-parametric-surface
#import "@preview/fletcher:0.5.4" as fletcher: diagram, edge, node
#set page(paper: "a4", margin: (x: 2.6cm, y: 2.8cm), numbering: "1 : 1")
#set par(justify: true, leading: 0.52em)
#let FONT_SIZE = 18pt;
#set text(font: "FreeSerif", size: FONT_SIZE, lang: "us")
#show math.equation: set text(font: "Euler Math", size: (FONT_SIZE * 1.0), lang: "en")
#set heading(numbering: none)
#show heading.where(level: 1): it => {
rect(inset: FONT_SIZE / 2)[#it]
}
#align(center)[
#text(size: FONT_SIZE * 2, weight: "bold")[#underline[exercise 3]]
]
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)
#outline(title: none)
#v(42pt)
#pagebreak()
= problem 1
== a) & b)
using the trapezoidal rule we can estimate
$
(1) quad I_[0,1][exp] := integral_0^1 e^x dd(x), wide
(2) quad I_[0,1][ln] := integral_0^1 ln(x) dd(x)
$
let us solve both analytically first, starting with $(1)$
$
integral_0^1 e^x dd(x) = evaluated(e^x)_0^1 = e - 1
$
then $(2)$
$
integral_0^1 ln(x) dd(x) & = [x ln(x) - 1/2 dot x^2 / x - 1/6 dot x^3 / x^2
- 1/12 dot x^4 / x^3 - dots.c]_0^1 \
& = -underbracket((1/2 + 1/6 + 1/12 + dots.c), 1)
- cancel(lim_(t -> 0) t ln(t)) \
& = -1,
$
because with $p(x) = x^2 + 3 x + 2$ we get
$
2 + 6 + 12 + dots.c = p(0) + p(1) + dots.c
$
so we can compute the telescope sum
$
sum_(k=0)^oo 1/p(k) & = sum_(k=0)^oo 1/(k^2 + 3 k + 2) \
& = sum_(k=0)^oo 1/((k+1)(k+2)) \
& = sum_(k=0)^oo (1/(k+1) - 1/(k+2)) \
& = 1 - cancel(1/2 + 1/2) - cancel(1/3 + 1/3) + dots.c \
& = 1.
$
now we know what to expect from our estimates.
recall the trapezoidal rule
$
// I_[a, b][f] approx T_[a, b][f] := (b-a)/2 (f(b) - f(a))
I_[a, b][f] approx T_[a, b][f] := (b-a)/2 sum_(i=0)^(n-1) (f(x_(i+1)) - f(x_i))
$
in our case $a = 0$ and $b = 1$. for $(1) med f(x) = e^x$ we obtain
$
T_[0, 1][exp] = 1/2 (e - 1),
$
which yields an error of
$
e - 1 - 1/2 (e - 1) = 1/2 (e - 1).
$
for $(2) med f(x) = ln(x)$ we obtain
$
T_[0, 1][ln] = 1/2 (lim_(t->0) ln(t) - ln(1)) = 1/2 (-oo - 0) = -oo
$
which yields an error of $oo$.
thus we can see that using the trapezoidal rule for $ln(x)$ diverges and proves
to be unwieldy. for $exp(x)$ we can see that it was off by half the actual
value.
== c)
recall the upper bound of the error for the trapezoidal rule
$
abs(E_[a,b][f]) <= (b-a)^3 / 12 dot max_(xi in [a,b]) abs(f''(xi))
$
which is for $f = exp$
$
E_[0, 1][exp] = e/12 approx #{ calc.round(calc.e / 12, digits: 3) }
$
as opposed to our previous $1/2 (e - 1)
= #{ calc.round((calc.e - 1) / 2, digits: 3) }$.
== e)
telescope sum ish
overlapping edges
= problem 3
== a)
to find an orthogonal basis $p_j (x)$ from the given canonical basis
$
#let phi = $phi.alt$
phi_0(x) equiv 1, med
phi_1(x) = x, med
phi_2(x) = x^2, med
phi_3(x) = x^3,
$
we can use the gram-schmidt process.
recall that
$
p_j (x) = phi_j (x) - sum_(k=0)^(j-1) {(integral_0^1 phi_j (x) p_k (x) dd(x))
/(integral_0^1 [p_k (x)]^2 dd(x))} p_k (x),
$
and notice that $p_0(x) equiv 1$.
thus we obtain
$
p_1(x) & = phi_1(x) - (integral_0^1 phi_1(x) p_0(x) dd(x))
/ (integral_0^1 [p_0(x)]^2 dd(x)) p_0 (x) \
& = x - (integral_0^1 x dd(x))/(integral_0^1 dd(x))
= x - 1/2, \
p_2(x) & = phi_2(x) - (integral_0^1 phi_2(x) p_1(x) dd(x))
/ (integral_0^1 [p_1(x)]^2 dd(x)) p_1 (x) \
& - (integral_0^1 phi_2(x) p_0(x) dd(x))
/ (integral_0^1 [p_0(x)]^2 dd(x)) p_0 (x) \
& = x^2 - (integral_0^1 x^2 (x - 1/2) dd(x))
/ (integral_0^1 [x-1/2]^2 dd(x)) (x - 1/2) \
& - (integral_0^1 x^2 dd(x)) / (integral_0^1 dd(x))
= x^2 - x + 1/6 \
p_3(x) & = limits(dots)^#[magic] = x^3 - 3/2 x^2 + 3/5 x - 1/20
$
== b)
we perform polynomial division to find the remaining two roots and obtain
$
p_3 (x) : (x - 1/2) = x^2 - x + 1/10 \
=> x = 1 / 2 plus.minus 1/2 sqrt(3/5)
$
so
$
x_0 & = 1/2 - 1/2 sqrt(3/5), \
x_1 & = 1/2, \
x_2 & = 1/2 + 1/2 sqrt(3/5).
$
== c)
let
$
w_i = integral_0^1 ell_i (x) dd(x)
$
with
$
ell_k (x) = product_(i = 0\ i != k)^(n - 1) (x - x_i) / (x_k - x_i)
$
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) \
$