mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-14 13:54:06 +01:00
Fix TP1 in Numerical methods
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T14:27:00.244402Z",
|
||||
"start_time": "2025-03-03T14:27:00.241231Z"
|
||||
"end_time": "2025-03-04T12:51:01.523548Z",
|
||||
"start_time": "2025-03-04T12:51:01.520087Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -15,7 +15,7 @@
|
||||
],
|
||||
"id": "fe01d49f9c6740ce",
|
||||
"outputs": [],
|
||||
"execution_count": 100
|
||||
"execution_count": 259
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
@@ -27,8 +27,8 @@
|
||||
"metadata": {
|
||||
"collapsed": true,
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T15:03:25.306403Z",
|
||||
"start_time": "2025-03-03T15:03:25.302289Z"
|
||||
"end_time": "2025-03-04T12:51:01.559159Z",
|
||||
"start_time": "2025-03-04T12:51:01.555615Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -42,21 +42,21 @@
|
||||
],
|
||||
"id": "initial_id",
|
||||
"outputs": [],
|
||||
"execution_count": 169
|
||||
"execution_count": 260
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-04T12:48:26.892060Z",
|
||||
"start_time": "2025-03-04T12:48:26.888087Z"
|
||||
"end_time": "2025-03-04T12:51:01.565527Z",
|
||||
"start_time": "2025-03-04T12:51:01.562740Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"def euler_explicit(N, T, y0, f, args=()):\n",
|
||||
"def euler_explicit(N, T, y0, f, type=int, args=()):\n",
|
||||
" h = T / N\n",
|
||||
" t = np.linspace(0, T, N + 1)\n",
|
||||
" y = np.zeros(N + 1, dtype=complex)\n",
|
||||
" y = np.zeros(N + 1, dtype=type)\n",
|
||||
" y[0] = y0\n",
|
||||
" for n in range(N):\n",
|
||||
" y[n + 1] = y[n] + h * f(t[n], y[n], *args)\n",
|
||||
@@ -64,13 +64,13 @@
|
||||
],
|
||||
"id": "f447a3bdff49e850",
|
||||
"outputs": [],
|
||||
"execution_count": 244
|
||||
"execution_count": 261
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T15:26:18.887962Z",
|
||||
"start_time": "2025-03-03T15:26:18.799687Z"
|
||||
"end_time": "2025-03-04T12:51:01.639877Z",
|
||||
"start_time": "2025-03-04T12:51:01.582392Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -100,13 +100,13 @@
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"execution_count": 218
|
||||
"execution_count": 262
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T15:25:45.054499Z",
|
||||
"start_time": "2025-03-03T15:25:45.049904Z"
|
||||
"end_time": "2025-03-04T12:51:01.657056Z",
|
||||
"start_time": "2025-03-04T12:51:01.654570Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -122,13 +122,13 @@
|
||||
],
|
||||
"id": "57527c2e5eb6d17d",
|
||||
"outputs": [],
|
||||
"execution_count": 214
|
||||
"execution_count": 263
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T15:25:51.105580Z",
|
||||
"start_time": "2025-03-03T15:25:51.038176Z"
|
||||
"end_time": "2025-03-04T12:51:01.739113Z",
|
||||
"start_time": "2025-03-04T12:51:01.672072Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -159,7 +159,7 @@
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"execution_count": 216
|
||||
"execution_count": 264
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
@@ -170,8 +170,8 @@
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T15:25:14.888616Z",
|
||||
"start_time": "2025-03-03T15:25:14.884827Z"
|
||||
"end_time": "2025-03-04T12:51:01.757489Z",
|
||||
"start_time": "2025-03-04T12:51:01.754373Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -185,13 +185,13 @@
|
||||
],
|
||||
"id": "61588e94b56ea779",
|
||||
"outputs": [],
|
||||
"execution_count": 208
|
||||
"execution_count": 265
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T15:25:15.302160Z",
|
||||
"start_time": "2025-03-03T15:25:15.298178Z"
|
||||
"end_time": "2025-03-04T12:51:01.776543Z",
|
||||
"start_time": "2025-03-04T12:51:01.773086Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -207,13 +207,13 @@
|
||||
],
|
||||
"id": "a32f0facb958a1a0",
|
||||
"outputs": [],
|
||||
"execution_count": 209
|
||||
"execution_count": 266
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T15:25:15.672410Z",
|
||||
"start_time": "2025-03-03T15:25:15.667465Z"
|
||||
"end_time": "2025-03-04T12:51:01.794953Z",
|
||||
"start_time": "2025-03-04T12:51:01.791398Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -231,13 +231,13 @@
|
||||
],
|
||||
"id": "ca061c36b09f7200",
|
||||
"outputs": [],
|
||||
"execution_count": 210
|
||||
"execution_count": 267
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T15:25:16.031135Z",
|
||||
"start_time": "2025-03-03T15:25:16.028109Z"
|
||||
"end_time": "2025-03-04T12:51:01.814042Z",
|
||||
"start_time": "2025-03-04T12:51:01.810178Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -257,13 +257,13 @@
|
||||
],
|
||||
"id": "afc8571b14a6b464",
|
||||
"outputs": [],
|
||||
"execution_count": 211
|
||||
"execution_count": 268
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T18:10:51.913835Z",
|
||||
"start_time": "2025-03-03T18:10:51.827148Z"
|
||||
"end_time": "2025-03-04T12:51:01.947339Z",
|
||||
"start_time": "2025-03-04T12:51:01.876657Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -298,13 +298,13 @@
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"execution_count": 235
|
||||
"execution_count": 269
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-03T18:10:54.382031Z",
|
||||
"start_time": "2025-03-03T18:10:54.014044Z"
|
||||
"end_time": "2025-03-04T12:51:02.453901Z",
|
||||
"start_time": "2025-03-04T12:51:01.967378Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -356,7 +356,7 @@
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"execution_count": 236
|
||||
"execution_count": 270
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
@@ -367,16 +367,16 @@
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-04T12:48:41.100446Z",
|
||||
"start_time": "2025-03-04T12:48:41.096706Z"
|
||||
"end_time": "2025-03-04T12:51:02.474489Z",
|
||||
"start_time": "2025-03-04T12:51:02.471385Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"def euler_implicit(N, T, u0, lam):\n",
|
||||
"def euler_implicit(N, T, u0, lam, type=int):\n",
|
||||
" h = T / N\n",
|
||||
" t = np.linspace(0, T, N + 1)\n",
|
||||
" u = np.zeros(N + 1, dtype=complex)\n",
|
||||
" u = np.zeros(N + 1, dtype=type)\n",
|
||||
" u[0] = u0\n",
|
||||
" for n in range(N):\n",
|
||||
" u[n + 1] = u[n] / (1 - lam * h)\n",
|
||||
@@ -384,13 +384,13 @@
|
||||
],
|
||||
"id": "4484c71f50b8e691",
|
||||
"outputs": [],
|
||||
"execution_count": 246
|
||||
"execution_count": 271
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-04T12:48:58.948153Z",
|
||||
"start_time": "2025-03-04T12:48:58.791130Z"
|
||||
"end_time": "2025-03-04T12:51:02.644858Z",
|
||||
"start_time": "2025-03-04T12:51:02.493576Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
@@ -404,8 +404,8 @@
|
||||
"N = 400\n",
|
||||
"x0 = 1\n",
|
||||
"\n",
|
||||
"t, x_appr_EE = euler_explicit(N, T, x0, f, args=(lam,))\n",
|
||||
"_, x_appr_EI = euler_implicit(N, T, x0, lam)\n",
|
||||
"t, x_appr_EE = euler_explicit(N, T, x0, f, type=complex, args=(lam,))\n",
|
||||
"_, x_appr_EI = euler_implicit(N, T, x0, lam, type=complex)\n",
|
||||
"x_exact = x0 * np.exp(lam * t)\n",
|
||||
"\n",
|
||||
"# Plot the real parts\n",
|
||||
@@ -444,15 +444,20 @@
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"execution_count": 250
|
||||
"execution_count": 272
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-03-04T12:51:02.662942Z",
|
||||
"start_time": "2025-03-04T12:51:02.661576Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"outputs": [],
|
||||
"execution_count": null,
|
||||
"source": "",
|
||||
"id": "aeb67c5158f41a0b"
|
||||
"id": "aeb67c5158f41a0b",
|
||||
"outputs": [],
|
||||
"execution_count": null
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
Reference in New Issue
Block a user