diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2025-04-24 17:39:37 -0600 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2025-04-24 17:39:37 -0600 |
| commit | 2d2b7b9f5731dc5c7bda29c917a6cc5f17b5160e (patch) | |
| tree | b566dc6e44f9e63abc94a18f6697010ea981ab89 /tutorials/module_1/arrays.ipynb | |
| parent | e53c35223bed9a32f1e9cd3fe75caf344d4b5c7e (diff) | |
Updated markdown formatting for latex conversion.
Diffstat (limited to 'tutorials/module_1/arrays.ipynb')
| -rw-r--r-- | tutorials/module_1/arrays.ipynb | 100 |
1 files changed, 55 insertions, 45 deletions
diff --git a/tutorials/module_1/arrays.ipynb b/tutorials/module_1/arrays.ipynb index efb14bb..7fe777d 100644 --- a/tutorials/module_1/arrays.ipynb +++ b/tutorials/module_1/arrays.ipynb @@ -22,11 +22,12 @@ "A three-dimensional array would be like a set of tables, perhaps stacked as though they were printed on separate pages. If we visualize the position of each element as a position in space. Then we can represent the value of the element as a property. In other words, if we were to analyze the stress concentration of an aluminum block, the property would be stress.\n", "\n", "- From [Numpy documentation](https://numpy.org/doc/2.2/user/absolute_beginners.html)\n", - "\n", + "\n", "\n", "If the load on this block changes over time, then we may want to add a 4th dimension i.e. additional sets of 3-D arrays for each time increment. As you can see - the more dimensions we add, the more complicated of a problem we have to solve. It is possible to increase the number of dimensions to the n-th order. This course we will not be going beyond dimensional analysis.\n", "\n", "---\n", + "\n", "# Numpy - the python's array library\n", "\n", "In this tutorial we will be introducing arrays and we will be using the numpy library. Arrays, lists, vectors, matrices, sets - You might've heard of them before, they all store data. In programming, an array is a variable that can hold more than one value at a time. We will be using the Numpy python library to create arrays. Since we already have installed Numpy previously, we can start using the package.\n", @@ -42,6 +43,7 @@ "- `as` - gives the library an alias in your script. It's common convention in Python programming to make the code shorter and more readable. We will be using *np* as it's a standard using in many projects.\n", "\n", "---\n", + "\n", "# Creating arrays\n", "Now that we have imported the library we can create a one dimensional array or *vector* with three elements.\n", "```python\n", @@ -78,12 +80,13 @@ "metadata": {}, "source": [ "# Practice Problem\n", + "\n", "Problem statement" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "id": "7f2bcfe9-6e3d-424d-a08f-520682b3bdb5", "metadata": {}, "outputs": [ @@ -113,6 +116,7 @@ "source": [ "## Numpy array creation functions\n", "Numpy comes with some built-in function that we can use to create arrays quickly. Here are a couple of functions that are commonly used in python.\n", + "\n", "### np.arange\n", "The `np.arange()` function returns an array with evenly spaced values within a specified range. It is similar to the built-in `range()` function in Python but returns a Numpy array instead of a list. The parameters for this function are the start value (inclusive), the stop value (exclusive), and the step size. If the step size is not provided, it defaults to 1.\n", "\n", @@ -158,7 +162,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "id": "0c5de840-6256-4de2-9845-1c80a12c062d", "metadata": {}, "outputs": [ @@ -182,6 +186,7 @@ "source": [ "## Working with Arrays\n", "Now that we have been introduced to some ways to create arrays using the Numpy functions let's start using them.\n", + "\n", "### Indexing\n", "Indexing in Python allows you to access specific elements within an array based on their position. This means you can directly retrieve and manipulate individual items as needed.\n", "\n", @@ -196,16 +201,19 @@ "```\n", "\n", "Due to the nature of zero-based indexing. If we want to call the value `4.054973` that will be the 3rd index. \n", + "\n", "### Operations on arrays\n", "- Arithmetic operations (`+`, `-`, `*`, `/`, `**`)\n", "- `np.add()`, `np.subtract()`, `np.multiply()`, `np.divide()`\n", "- `np.dot()` for dot product\n", "- `np.matmul()` for matrix multiplication\n", "- `np.linalg.inv()`, `np.linalg.det()` for linear algebra\n", + " \n", "#### Statistics\n", "- `np.mean()`, `np.median()`, `np.std()`, `np.var()`\n", "- `np.min()`, `np.max()`, `np.argmin()`, `np.argmax()`\n", "- Summation along axes: `np.sum(arr, axis=0)`\n", + "\n", "#### Combining arrays\n", "- Concatenation: `np.concatenate((arr1, arr2), axis=0)`\n", "- Stacking: `np.vstack()`, `np.hstack()`\n", @@ -215,24 +223,7 @@ }, { "cell_type": "markdown", - "id": "b1194250-2861-4001-899c-ced19f0f34ee", - "metadata": {}, - "source": [ - "## Practice problem\n", - "Problem statement here" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "777186e0-f734-4bc4-93f0-6746b428f821", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "29f020bf-b714-49a7-96bf-4e20138c7722", + "id": "e7d2add3-0806-49a0-9b85-4b23e96eca7e", "metadata": {}, "source": [ "# Exercise\n", @@ -240,28 +231,55 @@ "\n", "A simply supported bridge of length L=20L = 20L=20 m is subjected to three point loads:\n", "\n", - "- $P1=10P_1 = 10P1=10 kN$ at $x=5x = 5x=5 m$\n", - "- $P2=15P_2 = 15P2=15 kN$ at $x=10x = 10x=10 m$\n", - "- $P3=20P_3 = 20P3=20 kN$ at $x=15x = 15x=15 m$\n", + "- $P1=1010 kN$ at $x=5m$\n", + "- $P2=15 kN$ at $x=10m$\n", + "- $P3=20 kN$ at $x=15m$\n", "\n", "The bridge is supported by two reaction forces at points AAA (left support) and BBB (right support). We assume the bridge is in static equilibrium, meaning the sum of forces and sum of moments about any point must be zero.\n", "\n", "#### Equilibrium Equations:\n", "\n", "1. **Sum of Forces in the Vertical Direction**:\n", - " $RA+RB−P1−P2−P3=0R_A + R_B - P_1 - P_2 - P_3 = 0RA+RB−P1−P2−P3=0$\n", - "2. **Sum of Moments About Point A**:\n", - " $5P1+10P2+15P3−20RB=05 P_1 + 10 P_2 + 15 P_3 - 20 R_B = 05P1+10P2+15P3−20RB=0$\n", - "3. **Sum of Moments About Point B**:\n", - " $20RA−15P3−10P2−5P1=020 R_A - 15 P_3 - 10 P_2 - 5 P_1 = 020RA−15P3−10P2−5P1=0$\n", "\n", - "#### System of Equations:\n", + " $R_A + R_B - P_1 - P_2 - P_3 = 0$\n", + " \n", + "3. **Sum of Moments About Point A**:\n", "\n", - "{RA+RB−10−15−20=05(10)+10(15)+15(20)−20RB=020RA−5(10)−10(15)−15(20)=0\\begin{cases} R_A + R_B - 10 - 15 - 20 = 0 \\\\ 5(10) + 10(15) + 15(20) - 20 R_B = 0 \\\\ 20 R_A - 5(10) - 10(15) - 15(20) = 0 \\end{cases}⎩\n", + " $5 P_1 + 10 P_2 + 15 P_3 - 20 R_B = 0$\n", + " \n", + "5. **Sum of Moments About Point B**:\n", "\n", + " $20 R_A - 15 P_3 - 10 P_2 - 5 P_1 = 0$\n", "\n", - "## Solution\n", - "```python\n", + "\n", + "#### System of Equations:\n", + "\\begin{cases} R_A + R_B - 10 - 15 - 20 = 0 \\\\ 5(10) + 10(15) + 15(20) - 20 R_B = 0 \\\\ 20 R_A - 5(10) - 10(15) - 15(20) = 0 \\end{cases}" + ] + }, + { + "cell_type": "markdown", + "id": "54b896f0-97be-4ffb-b654-bb5108f99374", + "metadata": {}, + "source": [ + "### Solution" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "fc0244f6-d7f2-499a-a929-7f080d981b3e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Reaction force at A (R_A): 25.11 kN\n", + "Reaction force at B (R_B): -24.89 kN\n" + ] + } + ], + "source": [ "import numpy as np\n", "\n", "# Define the coefficient matrix A\n", @@ -279,21 +297,13 @@ "])\n", "\n", "# Solve the system of equations Ax = b\n", - "x = np.linalg.lstsq(A, b, rcond=None)[0] # Using least squares to handle potential overdetermination\n", + "# Using least squares to handle potential overdetermination\n", + "x = np.linalg.lstsq(A, b, rcond=None)[0] \n", "\n", "# Display the results\n", "print(f\"Reaction force at A (R_A): {x[0]:.2f} kN\")\n", - "print(f\"Reaction force at B (R_B): {x[1]:.2f} kN\")\n", - "```" + "print(f\"Reaction force at B (R_B): {x[1]:.2f} kN\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5c20b2fd-d9ce-49fa-b2d7-259e5b121bc7", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -312,7 +322,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.9" + "version": "3.13.2" } }, "nbformat": 4, |
