diff --git a/.ipynb_checkpoints/CE302-Week08-checkpoint.py b/.ipynb_checkpoints/CE302-Week08-checkpoint.py new file mode 100644 index 0000000..2eef47c --- /dev/null +++ b/.ipynb_checkpoints/CE302-Week08-checkpoint.py @@ -0,0 +1,59 @@ +############################################## +# 2021_0414-AAD: Multhithreading Example # +############################################## +# There are two approaches in code efficiency: +# 1. Parallel process : splitting the cpus +# 2. Creating paralle threads +############################### + +#%% IMPORTS + +import os, pandas as pd , time , datetime, numpy as np + +import threading # module for multithreading + +#%% +exitFlag = 0 + +class MyThread( threading.Thread) : + def __init__( self , threatID , name , my_delay) : + threading.Thread.__init__(self) + self.threatID = threatID + self.name = name + self.delay = my_delay + + def run(self): + print( f"Starting : {self.name}" ) + + print_time( self.name , self.delay , 5 ) + + print( f"Exiting : {self.name}") + +def print_time( threadName , my_delay , counter ): + + while counter : + if exitFlag : + threadName.exit() + time.sleep( my_delay ) + + print( f"{threadName} : time is {time.ctime(time.time())}") + + counter -= 1 + +#%% +# Crate the threats + +thread_1 = MyThread( 1 , "Thread name 1" , 1) + +thread_2 = MyThread( 2 , "Thread name 2" , 5) + +# Start the threads + +#%% + +thread_1.start() +thread_2.start() + +print( f"The file is ok") + +# %% diff --git a/.ipynb_checkpoints/CE302-Week09-checkpoint.ipynb b/.ipynb_checkpoints/CE302-Week09-checkpoint.ipynb index 899b319..93d8742 100644 --- a/.ipynb_checkpoints/CE302-Week09-checkpoint.ipynb +++ b/.ipynb_checkpoints/CE302-Week09-checkpoint.ipynb @@ -6,6 +6,295 @@ "source": [ "# CE302 ADVANCED PROGRAMMING TECHNIQUES FOR ENGINEERS" ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create the vectors" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "vect = np.array([1,2,3])" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([1, 2, 3])" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vect.T" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3,)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vect.T.shape" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create a matrix from the vectors" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "vec1 = np.array([1,2,3])\n", + "vec2 = np.array([3,4,5])\n", + "vec3 = np.array([4,5,6])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Variable Type Data/Info\n", + "-------------------------------\n", + "np module kages/numpy/__init__.py'>\n", + "os module da3/lib/python3.8/os.py'>\n", + "sys module \n", + "vec1 ndarray 3: 3 elems, type `int64`, 24 bytes\n", + "vec2 ndarray 3: 3 elems, type `int64`, 24 bytes\n", + "vec3 ndarray 3: 3 elems, type `int64`, 24 bytes\n", + "vect ndarray 3: 3 elems, type `int64`, 24 bytes\n" + ] + } + ], + "source": [ + "whos" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "myMatrice = np.vstack([vec1 , vec2 , vec3])" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1, 2, 3],\n", + " [3, 4, 5],\n", + " [4, 5, 6]])" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "myMatrice" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([1, 4, 6])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "myMatrice.diagonal()" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1, 3, 4],\n", + " [2, 4, 5],\n", + " [3, 5, 6]])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "myMatrice.T" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 3)" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "myMatrice.shape" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Summation" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 2, 4, 6],\n", + " [ 6, 8, 10],\n", + " [ 8, 10, 12]])" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "myMatrice + myMatrice" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 2, 4, 6],\n", + " [ 6, 8, 10],\n", + " [ 8, 10, 12]])" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.add( myMatrice , myMatrice)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Subtraction" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0, 0, 0],\n", + " [0, 0, 0],\n", + " [0, 0, 0]])" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "myMatrice - myMatrice\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/CE302-Week09.ipynb b/CE302-Week09.ipynb index 899b319..5012020 100644 --- a/CE302-Week09.ipynb +++ b/CE302-Week09.ipynb @@ -6,13 +6,697 @@ "source": [ "# CE302 ADVANCED PROGRAMMING TECHNIQUES FOR ENGINEERS" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create the vectors" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "output_type": "error", + "ename": "NameError", + "evalue": "name 'np' is not defined", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mvect\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mNameError\u001b[0m: name 'np' is not defined" + ] + } + ], + "source": [ + "vect = np.array([1,2,3])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "vect.T" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "vect.T.shape" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create a matrix from the vectors" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "vec1 = np.array([1,2,3])\n", + "vec2 = np.array([3,4,5])\n", + "vec3 = np.array([4,5,6])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "whos" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "myMatrice = np.vstack([vec1 , vec2 , vec3])" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1, 2, 3],\n", + " [3, 4, 5],\n", + " [4, 5, 6]])" + ] + }, + "metadata": {}, + "execution_count": 18 + } + ], + "source": [ + "myMatrice" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "myMatrice.diagonal()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "myMatrice.T" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "myMatrice.shape" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Summation" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 2, 4, 6],\n", + " [ 6, 8, 10],\n", + " [ 8, 10, 12]])" + ] + }, + "metadata": {}, + "execution_count": 12 + } + ], + "source": [ + "myMatrice + myMatrice" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 2, 4, 6],\n", + " [ 6, 8, 10],\n", + " [ 8, 10, 12]])" + ] + }, + "metadata": {}, + "execution_count": 13 + } + ], + "source": [ + "np.add( myMatrice , myMatrice)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Subtraction" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[0, 0, 0],\n", + " [0, 0, 0],\n", + " [0, 0, 0]])" + ] + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "\n", + "myMatrice - myMatrice\n" + ] + }, + { + "source": [ + "## Division" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 1., 1.],\n", + " [1., 1., 1.],\n", + " [1., 1., 1.]])" + ] + }, + "metadata": {}, + "execution_count": 15 + } + ], + "source": [ + "myMatrice / myMatrice" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 1., 1.],\n", + " [1., 1., 1.],\n", + " [1., 1., 1.]])" + ] + }, + "metadata": {}, + "execution_count": 16 + } + ], + "source": [ + "np.divide( myMatrice , myMatrice)" + ] + }, + { + "source": [ + "## Multiplication" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 1, 4, 9],\n", + " [ 9, 16, 25],\n", + " [16, 25, 36]])" + ] + }, + "metadata": {}, + "execution_count": 17 + } + ], + "source": [ + "myMatrice * myMatrice" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1, 2, 3],\n", + " [3, 4, 5],\n", + " [4, 5, 6]])" + ] + }, + "metadata": {}, + "execution_count": 19 + } + ], + "source": [ + "myMatrice" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[1., 2., 3.],\n", + " [3., 4., 5.],\n", + " [4., 5., 6.]])" + ] + }, + "metadata": {}, + "execution_count": 20 + } + ], + "source": [ + "np.sqrt( myMatrice * myMatrice )" + ] + }, + { + "source": [ + "### Dot multiplication" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[19, 25, 31],\n", + " [35, 47, 59],\n", + " [43, 58, 73]])" + ] + }, + "metadata": {}, + "execution_count": 21 + } + ], + "source": [ + "np.dot( myMatrice , myMatrice)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 1, 4, 9],\n", + " [ 9, 16, 25],\n", + " [16, 25, 36]])" + ] + }, + "metadata": {}, + "execution_count": 22 + } + ], + "source": [ + "np.multiply( myMatrice , myMatrice)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1, 2, 3])" + ] + }, + "metadata": {}, + "execution_count": 23 + } + ], + "source": [ + "vec1" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1, 4, 9])" + ] + }, + "metadata": {}, + "execution_count": 24 + } + ], + "source": [ + "vec1 * vec1" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "14" + ] + }, + "metadata": {}, + "execution_count": 25 + } + ], + "source": [ + "np.dot( vec1 , vec1)" + ] + }, + { + "source": [ + "## Determinant " + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "0.0" + ] + }, + "metadata": {}, + "execution_count": 26 + } + ], + "source": [ + "np.linalg.det(myMatrice)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "output_type": "error", + "ename": "LinAlgError", + "evalue": "Singular matrix", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mLinAlgError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinalg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minv\u001b[0m\u001b[0;34m(\u001b[0m \u001b[0mmyMatrice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m<__array_function__ internals>\u001b[0m in \u001b[0;36minv\u001b[0;34m(*args, **kwargs)\u001b[0m\n", + "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/numpy/linalg/linalg.py\u001b[0m in \u001b[0;36minv\u001b[0;34m(a)\u001b[0m\n\u001b[1;32m 544\u001b[0m \u001b[0msignature\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'D->D'\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misComplexType\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;34m'd->d'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 545\u001b[0m \u001b[0mextobj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_linalg_error_extobj\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_raise_linalgerror_singular\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 546\u001b[0;31m \u001b[0mainv\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_umath_linalg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msignature\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msignature\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mextobj\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mextobj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 547\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mwrap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mainv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult_t\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 548\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/numpy/linalg/linalg.py\u001b[0m in \u001b[0;36m_raise_linalgerror_singular\u001b[0;34m(err, flag)\u001b[0m\n\u001b[1;32m 86\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_raise_linalgerror_singular\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mflag\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 88\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mLinAlgError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Singular matrix\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 89\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_raise_linalgerror_nonposdef\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mflag\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mLinAlgError\u001b[0m: Singular matrix" + ] + } + ], + "source": [ + "np.linalg.inv( myMatrice)" + ] + }, + { + "source": [ + "## Linear Equations " + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "source": [ + "3x + 4y + 5z = 10 \n", + "\n", + "3y - 9z = 0\n", + "\n", + "x + 10z = 10\n", + "\n", + "Let's put them in matrix form\n", + "\n", + "$$ \\begin{bmatrix} 3 & 4 & 5 \\\\ 0 & 3 & -9 \\\\ 1 & 0 & 10 \\end{bmatrix} \\times \\begin{bmatrix}x\\\\y\\\\z\\end{bmatrix} = \\begin{bmatrix}10\\\\0\\\\10 \\end{bmatrix}$$ \n" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "source": [ + "**Remember __the Gauss elimination, Gauss-Jordan elimination, LU decomposition__ ...**" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "a_matrice = np.array([[3,4,5],[0,3,-9],[1,0,10]])" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 3, 4, 5],\n", + " [ 0, 3, -9],\n", + " [ 1, 0, 10]])" + ] + }, + "metadata": {}, + "execution_count": 29 + } + ], + "source": [ + "a_matrice" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [], + "source": [ + "RHS_matrice = np.array([10,0,10])" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([-5.38461538, 4.61538462, 1.53846154])" + ] + }, + "metadata": {}, + "execution_count": 31 + } + ], + "source": [ + "np.linalg.solve( a_matrice , RHS_matrice)" + ] + }, + { + "source": [ + "$$ \\frac{\\begin{bmatrix} 3 & 4 & 5 \\\\ 0 & 3 & -9 \\\\ 1 & 0 & 10 \\end{bmatrix} \\times \\begin{bmatrix}x\\\\y\\\\z\\end{bmatrix}}{\\begin{bmatrix} 3 & 4 & 5 \\\\ 0 & 3 & -9 \\\\ 1 & 0 & 10 \\end{bmatrix}} = \\frac {\\begin{bmatrix}10\\\\0\\\\10 \\end{bmatrix} }{\\begin{bmatrix} 3 & 4 & 5 \\\\ 0 & 3 & -9 \\\\ 1 & 0 & 10 \\end{bmatrix} } $$ " + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([[ 0.76923077, -1.02564103, -1.30769231],\n", + " [-0.23076923, 0.64102564, 0.69230769],\n", + " [-0.07692308, 0.1025641 , 0.23076923]])" + ] + }, + "metadata": {}, + "execution_count": 32 + } + ], + "source": [ + "np.linalg.inv(a_matrice)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([-5.38461538, 4.61538462, 1.53846154])" + ] + }, + "metadata": {}, + "execution_count": 34 + } + ], + "source": [ + "np.dot( np.linalg.inv( a_matrice), RHS_matrice)" + ] + }, + { + "source": [ + "In CE312 class, you'll solve the [K] . {U} = {P} \n", + "\n", + "K : stifness matrix\n", + "\n", + "U : Displacement matrix\n", + "\n", + "P : Load matrix" + ], + "cell_type": "markdown", + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "39.000000000000014" + ] + }, + "metadata": {}, + "execution_count": 35 + } + ], + "source": [ + "np.linalg.det( a_matrice)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" + "name": "python385jvsc74a57bd0bdc7d1c825d389c93c370bd8dbc0537723ed308b1e45edf84765b71ae8b74924", + "display_name": "Python 3.8.5 64-bit ('anaconda3': virtualenv)" }, "language_info": { "codemirror_mode": { @@ -29,4 +713,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file