From 498f813d2d486cebce251d9b34d43a31f5e2fb75 Mon Sep 17 00:00:00 2001 From: philippun Date: Tue, 8 Aug 2023 12:02:30 +0200 Subject: [PATCH] BTCS create_coeff_matrix --- proto/BTCS.ipynb | 82 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/proto/BTCS.ipynb b/proto/BTCS.ipynb index ca75a32..babe844 100644 --- a/proto/BTCS.ipynb +++ b/proto/BTCS.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -68,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -90,6 +90,84 @@ " return delta_t / (2 * delta_x**2)" ] }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "# creates the coeffiecient matrix for a given row\n", + "def create_coeff_matrix(alpha_x, row_index, s_x, transpose=False):\n", + " if (transpose):\n", + " alpha_x = alpha_x.transpose()\n", + "\n", + " cm = np.zeros((alpha_x.shape[0]+2,alpha_x.shape[1]+2))\n", + "\n", + " offset = 2\n", + " r = row_index\n", + " for i in range(2, cm.shape[0]-2):\n", + " j = offset\n", + " cm[i,j-1] = -s_x * alpha_interblock(alpha_x[r, j-1], alpha_x[r, j])\n", + " cm[i,j] = 1 + s_x * (alpha_interblock(alpha_x[r,j], alpha_x[r, j+1]) + alpha_interblock(alpha_x[r, j], alpha_x[r, j-1]))\n", + " cm[i,j+1] = -s_x * alpha_interblock(alpha_x[r, j], alpha_x[r, j+1])\n", + "\n", + " offset += 1\n", + "\n", + " return cm\n", + "\n", + "# creates the solution vector for a given row\n", + "def create_solution_vector(concentrations, alpha_y, row_index, s_x, transpose=False):\n", + " pass\n", + "\n", + "\n", + "def solve_row(A, b):\n", + " # use existing implementation\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "ename": "IndexError", + "evalue": "index 5 is out of bounds for axis 1 with size 5", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[17], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m result \u001b[39m=\u001b[39m create_coeff_matrix(np\u001b[39m.\u001b[39;49mrandom\u001b[39m.\u001b[39;49mrandom_sample((\u001b[39m5\u001b[39;49m,\u001b[39m5\u001b[39;49m)), \u001b[39m0\u001b[39;49m, \u001b[39m3\u001b[39;49m)\n\u001b[1;32m 2\u001b[0m \u001b[39mprint\u001b[39m(result)\n", + "Cell \u001b[0;32mIn[16], line 13\u001b[0m, in \u001b[0;36mcreate_coeff_matrix\u001b[0;34m(alpha_x, row_index, s_x, transpose)\u001b[0m\n\u001b[1;32m 11\u001b[0m j \u001b[39m=\u001b[39m offset\n\u001b[1;32m 12\u001b[0m cm[i,j\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m] \u001b[39m=\u001b[39m \u001b[39m-\u001b[39ms_x \u001b[39m*\u001b[39m alpha_interblock(alpha_x[r, j\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m], alpha_x[r, j])\n\u001b[0;32m---> 13\u001b[0m cm[i,j] \u001b[39m=\u001b[39m \u001b[39m1\u001b[39m \u001b[39m+\u001b[39m s_x \u001b[39m*\u001b[39m (alpha_interblock(alpha_x[r,j], alpha_x[r, j\u001b[39m+\u001b[39;49m\u001b[39m1\u001b[39;49m]) \u001b[39m+\u001b[39m alpha_interblock(alpha_x[r, j], alpha_x[r, j\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m]))\n\u001b[1;32m 14\u001b[0m cm[i,j\u001b[39m+\u001b[39m\u001b[39m1\u001b[39m] \u001b[39m=\u001b[39m \u001b[39m-\u001b[39ms_x \u001b[39m*\u001b[39m alpha_interblock(alpha_x[r, j], alpha_x[r, j\u001b[39m+\u001b[39m\u001b[39m1\u001b[39m])\n\u001b[1;32m 16\u001b[0m offset \u001b[39m+\u001b[39m\u001b[39m=\u001b[39m \u001b[39m1\u001b[39m\n", + "\u001b[0;31mIndexError\u001b[0m: index 5 is out of bounds for axis 1 with size 5" + ] + } + ], + "source": [ + "result = create_coeff_matrix(np.random.random_sample((5,5)), 0, 3)\n", + "print(result)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "3\n", + "4\n" + ] + } + ], + "source": [ + "for i in range(2,5):\n", + " print(i)" + ] + }, { "cell_type": "code", "execution_count": null,