Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added Gauss and LU
  • Loading branch information
rcc02007 committed Oct 6, 2017
1 parent b93e0c1 commit e7abd64
Show file tree
Hide file tree
Showing 21 changed files with 8,096 additions and 66 deletions.
Expand Up @@ -205,7 +205,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -227,18 +227,25 @@
" 1 2 3 4\n",
" 5 6 7 8\n",
" 9 10 11 12\n",
"\n",
"C =\n",
"\n",
" 20 28 36 44\n",
" 38 44 50 56\n",
"\n"
]
}
],
"source": [
"A=[5,3,0;1,2,3] \n",
"B=[1,2,3,4;5,6,7,8;9,10,11,12]"
"B=[1,2,3,4;5,6,7,8;9,10,11,12]\n",
"C=A*B;\n",
"C"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -372,10 +379,19 @@
"\n",
"Consider 4 masses connected in series to 4 springs with K=10 N/m. What are the final positions of the masses? \n",
"\n",
"![Springs-masses](mass_springs.svg)\n",
"\n",
"The masses haves the following amounts, 1, 2, 3, and 4 kg for masses 1-4. Using a FBD for each mass:\n",
"![Springs-masses](mass_springs.png)\n",
"\n",
"The masses haves the following amounts, 1, 2, 3, and 4 kg for masses 1-4. Using a FBD for each mass:"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"$m_{1}g+k(x_{2}-x_{1})-kx_{1}=0$\n",
"\n",
"$m_{2}g+k(x_{3}-x_{2})-k(x_{2}-x_{1})=0$\n",
Expand Down Expand Up @@ -414,7 +430,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -426,20 +442,6 @@
"name": "stdout",
"output_type": "stream",
"text": [
"K =\n",
"\n",
" 20 -10 0 0\n",
" -10 20 -10 0\n",
" 0 -10 20 -10\n",
" 0 0 -10 10\n",
"\n",
"y =\n",
"\n",
" 9.8100\n",
" 19.6200\n",
" 29.4300\n",
" 39.2400\n",
"\n",
"x =\n",
"\n",
" 9.8100\n",
Expand All @@ -457,17 +459,21 @@
"m3=3;\n",
"m4=4;\n",
"g=9.81; % m/s^2\n",
"K=[2*k -k 0 0; -k 2*k -k 0; 0 -k 2*k -k; 0 0 -k k]\n",
"y=[m1*g;m2*g;m3*g;m4*g]\n",
"K=[2*k -k 0 0; -k 2*k -k 0; 0 -k 2*k -k; 0 0 -k k];\n",
"y=[m1*g;m2*g;m3*g;m4*g];\n",
"\n",
"x=K\\y"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Matrix Operations\n",
"## Special Matrices\n",
"\n",
"Identity matrix `eye(M,N)` **Assume M=N unless specfied**\n",
"\n",
Expand All @@ -487,8 +493,13 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Matrix operations\n",
"### Transpose\n",
"\n",
"The transpose of a matrix changes the rows -> columns and columns-> rows\n",
Expand All @@ -514,9 +525,12 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 13,
"metadata": {
"collapsed": false
"collapsed": false,
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
Expand Down Expand Up @@ -602,7 +616,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 15,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -619,15 +633,16 @@
"Diagonal Matrix\n",
"\n",
" 1 0 0\n",
" 0 1 0\n",
" 0 4 0\n",
" 0 0 1\n",
"\n",
"ans = 3\n"
"ans = 6\n"
]
}
],
"source": [
"id_m=eye(3)\n",
"id_m=eye(3);\n",
"id_m(2,2)=4\n",
"trace(id_m)"
]
},
Expand Down Expand Up @@ -658,7 +673,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 16,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -672,9 +687,9 @@
"text": [
"A =\n",
"\n",
" 0.5762106 0.3533174 0.7172134\n",
" 0.7061664 0.4863733 0.9423436\n",
" 0.4255961 0.0016613 0.3561407\n",
" 0.71624 0.28713 0.91248\n",
" 0.43423 0.50924 0.89731\n",
" 0.81776 0.15682 0.48825\n",
"\n"
]
}
Expand All @@ -685,7 +700,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 17,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -699,9 +714,9 @@
"text": [
"Ainv =\n",
"\n",
" 41.5613 -30.1783 -3.8467\n",
" 36.2130 -24.2201 -8.8415\n",
" -49.8356 36.1767 7.4460\n",
" -1.189272 -0.032028 2.281478\n",
" -5.750167 4.369462 2.716129\n",
" 3.838847 -1.349811 -2.645516\n",
"\n"
]
}
Expand All @@ -712,7 +727,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 18,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -726,9 +741,9 @@
"text": [
"B =\n",
"\n",
" 0.524529 0.470856 0.708116\n",
" 0.084491 0.730986 0.528292\n",
" 0.303545 0.782522 0.389282\n",
" 0.88372 0.43914 0.13476\n",
" 0.43439 0.34519 0.30337\n",
" 0.84604 0.86479 0.21558\n",
"\n"
]
}
Expand All @@ -739,7 +754,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 20,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -753,34 +768,22 @@
"text": [
"ans =\n",
"\n",
" -182.185 125.738 40.598\n",
" -133.512 97.116 17.079\n",
" 282.422 -200.333 -46.861\n",
"\n",
"ans =\n",
"\n",
" -182.185 125.738 40.598\n",
" -133.512 97.116 17.079\n",
" 282.422 -200.333 -46.861\n",
"\n",
"ans =\n",
"\n",
" 41.5613 36.2130 -49.8356\n",
" -30.1783 -24.2201 36.1767\n",
" -3.8467 -8.8415 7.4460\n",
" -1.189272 -5.750167 3.838847\n",
" -0.032028 4.369462 -1.349811\n",
" 2.281478 2.716129 -2.645516\n",
"\n",
"ans =\n",
"\n",
" 41.5613 36.2130 -49.8356\n",
" -30.1783 -24.2201 36.1767\n",
" -3.8467 -8.8415 7.4460\n",
" -1.189272 -5.750167 3.838847\n",
" -0.032028 4.369462 -1.349811\n",
" 2.281478 2.716129 -2.645516\n",
"\n"
]
}
],
"source": [
"inv(A*B)\n",
"inv(B)*inv(A)\n",
"%inv(A*B)\n",
"%inv(B)*inv(A)\n",
"\n",
"inv(A')\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion 09_Linear-Algebra/09_Linear-Algebra.ipynb
Expand Up @@ -379,7 +379,7 @@
"\n",
"Consider 4 masses connected in series to 4 springs with K=10 N/m. What are the final positions of the masses? \n",
"\n",
"![Springs-masses](mass_springs.svg)\n",
"![Springs-masses](mass_springs.png)\n",
"\n",
"The masses haves the following amounts, 1, 2, 3, and 4 kg for masses 1-4. Using a FBD for each mass:"
]
Expand Down
Binary file modified 09_Linear-Algebra/octave-workspace
Binary file not shown.

0 comments on commit e7abd64

Please sign in to comment.