Files
2025-02-Numerical/notes/2.ipynb
2025-11-10 17:24:53 +09:00

203 lines
4.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "7fc797ce",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.rcParams[\"font.family\"] = \"D2Coding\""
]
},
{
"cell_type": "markdown",
"id": "a869c82a",
"metadata": {},
"source": [
"# Linear Equation\n",
"\n",
"$$A\\cdot x = b$$\n",
"\n",
"* $A$: [m, n]\n",
"* $b$: [m, 1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e7357276",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "1113de3c",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"id": "3bed3d44",
"metadata": {},
"source": [
"## Gauss Elimination\n",
"\n",
"## Gauss-Jordan Elimination"
]
},
{
"cell_type": "markdown",
"id": "a5239ed9",
"metadata": {},
"source": [
"## LU decomposition\n",
"\n",
"$$A = LU$$\n",
"\n",
"$$Ax = b \\Rightarrow LUx = b \\Rightarrow \\\\\n",
"L^{-1}LUx = L^{-1}b \n",
"$$\n",
"\n",
"At that time, $Ux = c$ is easy to compute.\n",
"and compute $Lc = b$ to easily get $x$.\n",
"\n",
"\n",
"Various LUdcmps\n",
"* Doolittle $L_{ii} = 1$\n",
"* Crout $U_{ii} = 1$\n",
"* Cholesky $L_{ii} = U_{ii}$, which is appropriate for symmetric, positive-definite matrix\n",
"\n",
"### Crout Implementation\n",
"\n",
"$$\\begin{bmatrix}\n",
"a_{11} & a_{12} & \\cdots a_{1n} \\\\\n",
"a_{21} & a_{22} & \\cdots a_{2n} \\\\\n",
"\\vdots & \\vdots & \\ddots \\vdots \\\\\n",
"a_{n1} & a_{n2} & \\cdots a_{nn}\n",
"\\end{bmatrix} = \\begin{bmatrix}\n",
"l_{11} & 0 & \\cdots 0 \\\\\n",
"l_{21} & l_{22} & \\cdots 0 \\\\\n",
"\\vdots & \\vdots & \\ddots \\vdots \\\\\n",
"l_{n1} & l_{n2} & \\cdots l_{nn}\n",
"\\end{bmatrix}\\begin{bmatrix}\n",
"1 & u_{12} & \\cdots u_{1n} \\\\\n",
"0 & 1 & \\cdots u_{2n} \\\\\n",
"\\vdots & \\vdots & \\ddots \\vdots \\\\\n",
"0 & 0 & \\cdots 1\n",
"\\end{bmatrix}$$\n",
"\n",
"$$\\begin{align*}\n",
"l_{i1} &= a_{i1} & (i = 1, 2, \\cdots, n) \\\\\n",
"u_{1j} &= a_{1j} / l_{11} & (j = 2, 3, \\cdots, n) \\\\\n",
"l_{ij} &= a_{ij} - \\sum_{k=1}^{j-1} {l_{ik} u_{kj}} & (j \\leq i, i = 2,3,\\cdots, n) \\\\\n",
"u_{ij} &= (a_{ij} - \\sum_{k=1}^{i-1} {l_{ik} u_{kj}}) / l_{ii} & (j > i, j = 3,4,\\cdots, n)\n",
"\\end{align*}$$"
]
},
{
"cell_type": "markdown",
"id": "8bd218a8",
"metadata": {},
"source": [
"# SVD(Singular Value Decomposition)\n",
"\n",
"**why?**\n",
"\n",
"**what?**\n",
"\n",
"$$A = UWV^T$$\n",
"\n",
"* $U$: [m, n]\n",
"* $W$: [n, n] diagonal with positive or zero\n",
"* $V$: [n, n] orthogonal\n",
"\n",
"\n",
"**properties**\n",
"\n",
"* orthonormality\n",
"* uniqueness"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "563d7aec",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(4, 3)\n"
]
},
{
"data": {
"text/plain": [
"array([[ 1., 0., -0.],\n",
" [ 1., 1., -1.],\n",
" [ 0., 1., -1.],\n",
" [-1., 1., 1.]])"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = np.array([[1, 0, 0], [1, 1, -1], [0, 1, -1], [-1, 1, 1]])\n",
"print(A.shape)\n",
"U, S, Vh = np.linalg.svd(A, False)"
]
},
{
"cell_type": "markdown",
"id": "fb89ad74",
"metadata": {},
"source": [
"## Homogeneous\n",
"\n",
"\n",
"## Nonhomogeneous\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "733012d2",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "2025-02-Numerical (3.12.11)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}