Compare commits
10 commits
7-solve-pr
...
coryab/edi
| Author | SHA1 | Date | |
|---|---|---|---|
|
4e633d13b5 |
|||
|
400e8a29df |
|||
|
996b99fca3 |
|||
|
|
271e3dd944 | ||
|
|
c42426847d | ||
|
|
13cbbc4e0e | ||
|
e407ce073e |
|||
|
f2f50ed3e4 |
|||
|
91cc7583af |
|||
| 6f5d71e1a4 |
7 changed files with 108 additions and 5 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -36,3 +36,9 @@
|
|||
*.log
|
||||
*.out
|
||||
*.bib
|
||||
*.synctex.gz
|
||||
*.bbl
|
||||
|
||||
# C++ specifics
|
||||
src/*
|
||||
!src/*.cpp
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,7 +1,9 @@
|
|||
\documentclass[english,notitlepage]{revtex4-1} % defines the basic parameters of the document
|
||||
%For preview: skriv i terminal: latexmk -pdf -pvc filnavn
|
||||
|
||||
|
||||
% Silence warning of revtex4-1
|
||||
\usepackage{silence}
|
||||
\WarningFilter{revtex4-1}{Repair the float}
|
||||
|
||||
% if you want a single-column, remove reprint
|
||||
|
||||
|
|
@ -13,7 +15,7 @@
|
|||
%% I recommend downloading TeXMaker, because it includes a large library of the most common packages.
|
||||
|
||||
\usepackage{physics,amssymb} % mathematical symbols (physics imports amsmath)
|
||||
\include{amsmath}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{graphicx} % include graphics such as plots
|
||||
\usepackage{xcolor} % set colors
|
||||
\usepackage{hyperref} % automagic cross-referencing (this is GODLIKE)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,14 @@
|
|||
\section*{Problem 1}
|
||||
|
||||
First, we rearrange the equation.
|
||||
|
||||
\begin{align*}
|
||||
- \frac{d^2u}{dx^2} &= 100 e^{-10x} \\
|
||||
\frac{d^2u}{dx^2} &= -100 e^{-10x} \\
|
||||
\end{align*}
|
||||
|
||||
Now we find $u(x)$.
|
||||
|
||||
% Do the double integral
|
||||
\begin{align*}
|
||||
u(x) &= \int \int \frac{d^2 u}{dx^2} dx^2 \\
|
||||
|
|
@ -10,7 +19,7 @@
|
|||
&= -e^{-10x} + c_1 x + c_2
|
||||
\end{align*}
|
||||
|
||||
Using the boundary conditions, we can find $c_1$ and $c_2$ as shown below:
|
||||
Using the boundary conditions, we can find $c_1$ and $c_2$
|
||||
|
||||
\begin{align*}
|
||||
u(0) &= 0 \\
|
||||
|
|
|
|||
|
|
@ -1,4 +1,37 @@
|
|||
|
||||
\section*{Problem 3}
|
||||
|
||||
% Show how it's derived and where we found the derivation.
|
||||
To derive the discretized version of the Poisson equation, we first need
|
||||
the Taylor expansion for $u(x)$ around $x$ for $x + h$ and $x - h$.
|
||||
|
||||
\begin{align*}
|
||||
u(x+h) &= u(x) + u'(x) h + \frac{1}{2} u''(x) h^2 + \frac{1}{6} u'''(x) h^3 + \mathcal{O}(h^4)
|
||||
\end{align*}
|
||||
|
||||
\begin{align*}
|
||||
u(x-h) &= u(x) - u'(x) h + \frac{1}{2} u''(x) h^2 - \frac{1}{6} u'''(x) h^3 + \mathcal{O}(h^4)
|
||||
\end{align*}
|
||||
|
||||
If we add the equations above, we get this new equation:
|
||||
|
||||
\begin{align*}
|
||||
u(x+h) + u(x-h) &= 2 u(x) + u''(x) h^2 + \mathcal{O}(h^4) \\
|
||||
u(x+h) - 2 u(x) + u(x-h) + \mathcal{O}(h^4) &= u''(x) h^2 \\
|
||||
u''(x) &= \frac{u(x+h) - 2 u(x) + u(x-h)}{h^2} + \mathcal{O}(h^2) \\
|
||||
u_i''(x) &= \frac{u_{i+1} - 2 u_i + u_{i-1}}{h^2} + \mathcal{O}(h^2) \\
|
||||
\end{align*}
|
||||
|
||||
We can then replace $\frac{d^2u}{dx^2}$ with the RHS (right-hand side) of the equation:
|
||||
|
||||
\begin{align*}
|
||||
- \frac{d^2u}{dx^2} &= f(x) \\
|
||||
\frac{ - u_{i+1} + 2 u_i - u_{i-1}}{h^2} + \mathcal{O}(h^2) &= f_i \\
|
||||
\end{align*}
|
||||
|
||||
And lastly, we leave out $\mathcal{O}(h^2)$ and change $u_i$ to $v_i$ to
|
||||
differentiate between the exact solution and the approximate solution,
|
||||
and get the discretized version of the equation:
|
||||
|
||||
\begin{align*}
|
||||
\frac{ - v_{i+1} + 2 v_i - v_{i-1}}{h^2} &= 100 e^{-10x_i} \\
|
||||
\end{align*}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,44 @@
|
|||
\section*{Problem 4}
|
||||
|
||||
% Show that each iteration of the discretized version naturally creates a matrix equation.
|
||||
|
||||
The value of $u(x_{0})$ and $u(x_{1})$ is known, using the discretized equation we can approximate the value of $f(x_{i}) = f_{i}$. This will result in a set of equations
|
||||
\begin{align*}
|
||||
- v_{0} + 2 v_{1} - v_{2} &= h^{2} \cdot f_{1} \\
|
||||
- v_{1} + 2 v_{2} - v_{3} &= h^{2} \cdot f_{2} \\
|
||||
\vdots & \\
|
||||
- v_{m-2} + 2 v_{m-1} - v_{m} &= h^{2} \cdot f_{m-1} \\
|
||||
\end{align*}
|
||||
|
||||
Rearranging the first and last equation, moving terms of known boundary values to the RHS
|
||||
\begin{align*}
|
||||
2 v_{1} - v_{2} &= h^{2} \cdot f_{1} + v_{0} \\
|
||||
- v_{1} + 2 v_{2} - v_{3} &= h^{2} \cdot f_{2} \\
|
||||
\vdots & \\
|
||||
- v_{m-2} + 2 v_{m-1} &= h^{2} \cdot f_{m-1} + v_{m} \\
|
||||
\end{align*}
|
||||
|
||||
We now have a number of linear eqations, corresponding to the number of unknown values, which can be represented as an augmented matrix
|
||||
\begin{align*}
|
||||
\left[
|
||||
\begin{matrix}
|
||||
2v_{1} & -v_{2} & 0 & \dots & 0 \\
|
||||
-v_{1} & 2v_{2} & -v_{3} & 0 & \\
|
||||
0 & -v_{2} & 2v_{3} & -v_{4} & \\
|
||||
\vdots & & & \ddots & \vdots \\
|
||||
0 & & & -v_{m-2} & 2v_{m-1} \\
|
||||
\end{matrix}
|
||||
\left|
|
||||
\,
|
||||
\begin{matrix}
|
||||
g_{1} \\
|
||||
g_{2} \\
|
||||
g_{2} \\
|
||||
\vdots \\
|
||||
g_{m-1} \\
|
||||
\end{matrix}
|
||||
\right.
|
||||
\right]
|
||||
\end{align*}
|
||||
where $g_{i} = h^{2} f_{i}$. An augmented matrix can be represented as $\boldsymbol{A} \vec{x} = \vec{b}$. In this case $\boldsymbol{A}$ is the coefficient matrix with a tridiagonal signature $(-1, 2, -1)$ and dimension $n \cross n$, where $n=m-2$.
|
||||
|
||||
|
|
|
|||
12
src/Makefile
Normal file
12
src/Makefile
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
CC=g++
|
||||
|
||||
all: simpleFile
|
||||
|
||||
simpleFile: simpleFile.o
|
||||
$(CC) -o $@ $^
|
||||
|
||||
%.o: %.cpp
|
||||
$(CC) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm *.o
|
||||
Loading…
Add table
Add a link
Reference in a new issue