summaryrefslogtreecommitdiff
path: root/PVCM/cama/en/ma35 Système matriciel -- Exercices.ipynb
diff options
context:
space:
mode:
authormartial.simon <martial.simon@epita.fr>2025-04-13 19:54:19 +0200
committermartial.simon <martial.simon@epita.fr>2025-04-13 19:54:19 +0200
commit66c3bbfa94d8a41e58adf154be25e6d86fee8e30 (patch)
tree9c5e998f324f2f60c1717759144da3f996c5ae1a /PVCM/cama/en/ma35 Système matriciel -- Exercices.ipynb
init: initial commit
Diffstat (limited to 'PVCM/cama/en/ma35 Système matriciel -- Exercices.ipynb')
-rw-r--r--PVCM/cama/en/ma35 Système matriciel -- Exercices.ipynb190
1 files changed, 190 insertions, 0 deletions
diff --git a/PVCM/cama/en/ma35 Système matriciel -- Exercices.ipynb b/PVCM/cama/en/ma35 Système matriciel -- Exercices.ipynb
new file mode 100644
index 0000000..5d74dcb
--- /dev/null
+++ b/PVCM/cama/en/ma35 Système matriciel -- Exercices.ipynb
@@ -0,0 +1,190 @@
+{
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "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.8.10"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2,
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "lang": "en"
+ },
+ "source": [
+ "## Vector Programming\n",
+ "\n",
+ "The aim of the exercises is\n",
+ "\n",
+ "* to have a program that gives the correct answer\n",
+ "* which is as fast as possible (and for this we use massively Numpy)\n",
+ "\n",
+ "Generally if you have nested `for` it's a bad sign."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "np.set_printoptions(precision=10, linewidth=150, suppress=True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "lang": "en"
+ },
+ "source": [
+ "## Partial Gaussian pivot method\n",
+ "\n",
+ "The announcement is in the course. We will check on the case which generates\n",
+ "rounding errors."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "lang": "en"
+ },
+ "source": [
+ "## Choleski factorization\n",
+ "\n",
+ "This is to decompose A into $A = B\\, B^T$ with B a lower triangular matrix. This is not possible\n",
+ "that if the matrix A is symmetric and positive definite (this is moreover a way of verifying that a\n",
+ "matrix is ​​positive definite).\n",
+ "\n",
+ "Write Choleski's algorithm that takes A and returns B (to guess the algorithm, try to find the\n",
+ "coefficients of B from the coefficients of A on a 4x4 matrix A)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "lang": "en"
+ },
+ "source": [
+ "Reminder: no nested `for` loops but vector and matrix operations (on sub-matrices).\n",
+ "\n",
+ "Create a positive definite symmetric matrix and verify that its program works."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "lang": "en"
+ },
+ "source": [
+ "## Improve Jacobi\n",
+ "\n",
+ "When we write an iteration of the Jacobi method with all the coefficients, we find that\n",
+ "if we calculate the new value of **x** element by element then when we want to update `x[1]`,\n",
+ "we already know `x[0]`. Ditto when we update `x[2]` we already know `x[0]` and `x[1]`, etc.\n",
+ "\n",
+ "The idea of ​​the improved version of Jacobi is to use the new value of `x[0]` and not the old one\n",
+ "as is the case in the algorithm of the course. So by using updated values ​​we can expect\n",
+ "converge faster.\n",
+ "\n",
+ "In this case, each iteration requires a line-by-line calculation and therefore a `for` loop within the `for` loop on\n",
+ "the iterations."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "lang": "en"
+ },
+ "source": [
+ "#### Test stop\n",
+ "\n",
+ "We will add an `error` argument to the function which indicates the desired precision of the result. Unfortunately, to know the accuracy of our calculation, it is necessary to know the solution. We could also calculate\n",
+ "${\\bf A \\, x}^t - {\\bf b}$ but it's also not the gap between ${\\bf x}^t$ and the solution (besides\n",
+ "it is a calculation in n² therefore cumbersome).\n",
+ "\n",
+ "Also we will look when the\n",
+ "convergence slows down and therefore we stop when\n",
+ "$||{\\bf x}^{t+1} - {\\bf x}^t|| < \\texttt{error}$."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "lang": "en"
+ },
+ "source": [
+ "#### Bonuses\n",
+ "\n",
+ "Rewrite the method without the `for` loop but taking the new values ​​of `x`. For this we will cut the matrix **A** into two triangular matrices."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# les méthodes de Numpy triu et tril seront utiles\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ]
+} \ No newline at end of file