89 lines
25 KiB
Plaintext
89 lines
25 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAEICAYAAAB25L6yAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAABE6klEQVR4nO3dd3hUVf7H8fdJIYH0TkghCb0kgSTSpKMUwYqu+sOKir33RUXX1cW1rAV3FVFRVOwoKnZBmpQEAoRQDCG9907a+f1xhxCQMoEkM0m+r+eZZzJz79z53mTyycm5556rtNYIIYSwXjaWLkAIIcTJSVALIYSVk6AWQggrJ0EthBBWToJaCCGsnAS1EEJYOQlq0WaUUk8qpT5opW1dp5Raf4bbGKeU2neS5SFKKa2UsjuT9xGitUlQC5RSKUqpWqWU9zHPbzcFV4gZ25iolMposyJbgdZ6ndZ6wOHHpv0+53S3p5Raavr+jGj2XF+lVItPTlBK/U0ptVEpVaWUWnOc5cOUUnGm5XFKqWHNliml1HNKqULT7TmllDrd/RLWR4JaHHYQuPLwA6VUONDDcuV0GEXAP1tpOy8DC49doJTqBnwNfAB4AO8BX5ueB5gHXAREAhHA+cDNrVCTsBIS1OKwZcA1zR5fC7zffAWllINS6gWlVJpSKlcp9YZSqrtSygn4HuillKow3XqZXtZNKfW+UqpcKbVbKRXTbHuDlFJrlFIlpmUXNFvmpZRaqZQqU0ptAfqcqHCl1HtKqftNXweYWrm3mx73UUoVKaVsmrf6lVLLgGDgG1O9DzXb5BzTPhYopeaf4vv2HhChlJpwivVOSmv9i9b6UyDrOIsnAnbAy1rrQ1rrVwEFTDYtvxZ4UWudobXOBF4ErjuTeoR1kaAWh20CXE3haQtcgdGCa24h0B8YBvQFAoA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ZFRUVvPrqq2RlZTFp0iQmTZrUtO78+fOJjIxk1KhR5OYabY+UlBQmT55MREQEU6ZMIS0tDYCDBw8yevRowsPDeeyxx8z6foqu48mVu4lPL+HFv0XSz8/l1C84HVrrU94AJ6AQcDNn/ejoaH2sxMTEpq+fXJmg//bGxla9Pbky4S/v2dzBgwf18OHDtdZaNzQ06LCwMF1QUHDS1zS3evVqPXPmTP3777/r8ePHa621njlzpl69erXWWuvevXvr/Px8rbXWW7du1RMmTNBaa71gwQJ99tln69raWh0fH6+7d++uV61apbXW+qKLLtIrVqzQtbW1evTo0TovL09rrfXHH3+sr7/+eq211hMmTNC33nprUx0LFizQzz//vNZa6xEjRugvv/xSa611dXW1rqys1HV1dbq0tFRrrXV+fr7u06ePbmxs1Fpr7eTkdNx9c3Jy0jt27NCzZ8/W1dXVOjIysml/tdb60Ucf1cuWLdNaa11cXKz79eunKyoq9Lvvvqtvv/32o2obPXq0rqmp0fn5+drT01PX1tbq2NhYPXToUF1RUaHLy8v14MGD9bZt25qer6ys1KWlpbpPnz5N+9bctddeqy+//HLd2Niov/rqK+3i4qJ37typGxoadFRUlN6+fbvOz8/X48aN0xUVFVprrRcuXKifeuqpv/xstNYa0CtXrtRaa/3ggw/qp59+Wmut9axZs/TSpUu11lq//fbb+sILL9Raa33++efr9957T2ut9aJFi477fWz++RZdxwebUnTvh7/V//5hzxlvC4jVJ8hUs9ro2rjQqVfb/KloHyEhIXh5ebF9+3Zyc3MZPnw4Xl4t36Xx48cDsH79erNfM2PGDOzt7QkPD6ehoYHp06cDEB4eTkpKCvv27SMhIYFzzz0XgIaGBvz9/Ztef/nll/9lm+Xl5WRmZnLxxRcDxkkXYJxY9Pe//521a9diY2NDZmYmubm59OzZ86Q1RkR
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"\n",
|
||
|
"t0 = 0\n",
|
||
|
"tf = 1\n",
|
||
|
"N = 100\n",
|
||
|
"\n",
|
||
|
"#Every variable is the same as the one given in Forward_Euler.py\n",
|
||
|
"\n",
|
||
|
"t = np.linspace(t0,tf,N)\n",
|
||
|
"y = np.zeros(N)\n",
|
||
|
"z = np.zeros(N)\n",
|
||
|
"w = np.zeros(N)\n",
|
||
|
"h = (tf-t0)/N\n",
|
||
|
"\n",
|
||
|
"y[0] = 1\n",
|
||
|
"y[1] = y[0] + h*y[0]\n",
|
||
|
"\n",
|
||
|
"for i in range (0,N-2):\n",
|
||
|
" y[i+2] = y[i+1] + h*(1.5*y[i+1]+0.5*y[i])\n",
|
||
|
"\n",
|
||
|
"w = np.exp(t) #we vectorized the subtraction instead of iterating through w\n",
|
||
|
"z = abs(y-w) #same here\n",
|
||
|
"\n",
|
||
|
"plt.plot(t,y, label = \"y - Numerical Method method\") #very simple plot of y,z,w\n",
|
||
|
"plt.plot(t,w,label = \"w - Actual\")\n",
|
||
|
"plt.plot(t,z,label = \"z - Error\")\n",
|
||
|
"plt.title(\"Method with N=%d\"%N)\n",
|
||
|
"plt.legend()\n",
|
||
|
"plt.show()\n",
|
||
|
"\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"interpreter": {
|
||
|
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
|
||
|
},
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3.9.10 64-bit",
|
||
|
"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.9.10"
|
||
|
},
|
||
|
"orig_nbformat": 4
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 2
|
||
|
}
|