Skip to content

Commit

Permalink
Created using Colab
Browse files Browse the repository at this point in the history
  • Loading branch information
GEORMC committed Oct 31, 2024
1 parent defff43 commit 02ab7b4
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions CentralDifferenceMethod.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"private_outputs": true,
"provenance": [],
"authorship_tag": "ABX9TyNbGIbKsIccowCM/6sLGwXo",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/GEORMC/Nnumerical_Methods_Course/blob/main/CentralDifferenceMethod.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "iyHe3OQBAUlA"
},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"# System parameters\n",
"m = 1.0 # mass in kg\n",
"c = 0.1 # damping coefficient in Ns/m\n",
"k = 2.0 # stiffness in N/m\n",
"F = 1.0 # external force in N (constant)\n",
"dt = 0.1 # time step in seconds\n",
"t_max = 1.0 # maximum time in seconds\n",
"\n",
"# Time steps\n",
"n_steps = int(t_max / dt) + 1\n",
"\n",
"# Initial conditions\n",
"u = np.zeros(n_steps) # displacement array\n",
"u[1] = 0.5 * F / m * dt**2 # initial displacement using approximation\n",
"\n",
"# Central Difference Method\n",
"for n in range(1, n_steps - 1):\n",
" # Apply the central difference formula\n",
" u[n + 1] = (F - c * (u[n] - u[n - 1]) / (2 * dt) - k * u[n]) / m * dt**2 + 2 * u[n] - u[n - 1]\n",
"\n",
"# Display results\n",
"time = np.arange(0, t_max + dt, dt)\n",
"result = np.column_stack((time, u))\n",
"\n"
]
}
]
}

0 comments on commit 02ab7b4

Please sign in to comment.