Skip to content

Commit 0132605

Browse files
committed
synced cells with lecture notes
1 parent 4f8047b commit 0132605

File tree

1 file changed

+98
-119
lines changed

1 file changed

+98
-119
lines changed

Tutorial_06b_MatrixAlgebra.ipynb

+98-119
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,98 @@
184184
"printmat(A')"
185185
]
186186
},
187+
{
188+
"cell_type": "markdown",
189+
"metadata": {},
190+
"source": [
191+
"## Vectors: Inner and Outer Products\n",
192+
"\n",
193+
"There are several different ways to think about a vector in applied mathematics: as a $K \\times 1$ matrix (a column vector), a $1 \\times K$ matrix (a row vector) or just a flat $K$ vector. Julia uses flat vectors but they are mostly interchangable with column vectors. \n",
194+
"\n",
195+
"The inner product of two (column) vectors with $K$ elements is calculated as `x'z` or `dot(x,y)` (textbook: $x'z$ or $x \\cdot z$) to get a scalar. (The dot is obtained by `\\cdot + TAB`, but this is sometimes hard to distinguish from or things like `x.z`.)\n",
196+
"\n",
197+
"In contrast, the outer product of two (column) vectors with $K$ elements is calculated as `x*z'` (textbook: $xz'$) to get a $K\\times K$ matrix."
198+
]
199+
},
200+
{
201+
"cell_type": "code",
202+
"execution_count": 5,
203+
"metadata": {},
204+
"outputs": [
205+
{
206+
"name": "stdout",
207+
"output_type": "stream",
208+
"text": [
209+
"\u001b[34m\u001b[1mx and z\u001b[22m\u001b[39m\n",
210+
" 10 2 \n",
211+
" 11 5 \n",
212+
"\n",
213+
"\u001b[34m\u001b[1mx'z: \u001b[22m\u001b[39m\n",
214+
" 75 \n",
215+
"\u001b[34m\u001b[1mx*z':\u001b[22m\u001b[39m\n",
216+
" 20 50 \n",
217+
" 22 55 \n",
218+
"\n"
219+
]
220+
}
221+
],
222+
"source": [
223+
"x = [10,11] #[10;11] gives the same\n",
224+
"z = [2,5]\n",
225+
"printblue(\"x and z\")\n",
226+
"printmat([x z])\n",
227+
"\n",
228+
"printblue(\"x'z: \")\n",
229+
"printlnPs(x'z) #dot(x,z) gives the same\n",
230+
"\n",
231+
"printblue(\"x*z':\")\n",
232+
"printmat(x*z')"
233+
]
234+
},
235+
{
236+
"cell_type": "markdown",
237+
"metadata": {},
238+
"source": [
239+
"## Vectors: Quadratic Forms\n",
240+
"\n",
241+
"A quadratic form ($A$ is an $n \\times n$ matrix and $x$ is an $n$ vector): `x'A*x` (textbook: $x'Ax$) to get a scalar. There is also the form `dot(x,A,x)`."
242+
]
243+
},
244+
{
245+
"cell_type": "code",
246+
"execution_count": 6,
247+
"metadata": {},
248+
"outputs": [
249+
{
250+
"name": "stdout",
251+
"output_type": "stream",
252+
"text": [
253+
"\u001b[34m\u001b[1mx:\u001b[22m\u001b[39m\n",
254+
" 10 \n",
255+
" 11 \n",
256+
"\n",
257+
"\u001b[34m\u001b[1mA:\u001b[22m\u001b[39m\n",
258+
" 1 3 \n",
259+
" 3 4 \n",
260+
"\n",
261+
"\u001b[34m\u001b[1mx'A*x: \u001b[22m\u001b[39m\n",
262+
" 1244 \n"
263+
]
264+
}
265+
],
266+
"source": [
267+
"A = [1 3;3 4]\n",
268+
"x = [10,11]\n",
269+
"\n",
270+
"printblue(\"x:\")\n",
271+
"printmat(x)\n",
272+
"printblue(\"A:\")\n",
273+
"printmat(A)\n",
274+
"\n",
275+
"printblue(\"x'A*x: \")\n",
276+
"printlnPs(x'A*x) #or dot(x,A,x)"
277+
]
278+
},
187279
{
188280
"cell_type": "markdown",
189281
"metadata": {},
@@ -206,7 +298,7 @@
206298
},
207299
{
208300
"cell_type": "code",
209-
"execution_count": 5,
301+
"execution_count": 7,
210302
"metadata": {
211303
"tags": []
212304
},
@@ -257,7 +349,7 @@
257349
},
258350
{
259351
"cell_type": "code",
260-
"execution_count": 6,
352+
"execution_count": 8,
261353
"metadata": {},
262354
"outputs": [
263355
{
@@ -302,7 +394,7 @@
302394
},
303395
{
304396
"cell_type": "code",
305-
"execution_count": 7,
397+
"execution_count": 9,
306398
"metadata": {},
307399
"outputs": [
308400
{
@@ -340,7 +432,7 @@
340432
},
341433
{
342434
"cell_type": "code",
343-
"execution_count": 8,
435+
"execution_count": 10,
344436
"metadata": {},
345437
"outputs": [
346438
{
@@ -375,98 +467,6 @@
375467
"printmat(1I[1:3,2])"
376468
]
377469
},
378-
{
379-
"cell_type": "markdown",
380-
"metadata": {},
381-
"source": [
382-
"## Vectors: Inner and Outer Products\n",
383-
"\n",
384-
"There are several different ways to think about a vector in applied mathematics: as a $K \\times 1$ matrix (a column vector), a $1 \\times K$ matrix (a row vector) or just a flat $K$ vector. Julia uses flat vectors but they are mostly interchangable with column vectors. \n",
385-
"\n",
386-
"The inner product of two (column) vectors with $K$ elements is calculated as `x'z` or `dot(x,y)` (textbook: $x'z$ or $x \\cdot z$) to get a scalar. (The dot is obtained by `\\cdot + TAB`, but this is sometimes hard to distinguish from or things like `x.z`.)\n",
387-
"\n",
388-
"In contrast, the outer product of two (column) vectors with $K$ elements is calculated as `x*z'` (textbook: $xz'$) to get a $K\\times K$ matrix."
389-
]
390-
},
391-
{
392-
"cell_type": "code",
393-
"execution_count": 9,
394-
"metadata": {},
395-
"outputs": [
396-
{
397-
"name": "stdout",
398-
"output_type": "stream",
399-
"text": [
400-
"\u001b[34m\u001b[1mx and z\u001b[22m\u001b[39m\n",
401-
" 10 2 \n",
402-
" 11 5 \n",
403-
"\n",
404-
"\u001b[34m\u001b[1mx'z: \u001b[22m\u001b[39m\n",
405-
" 75 \n",
406-
"\u001b[34m\u001b[1mx*z':\u001b[22m\u001b[39m\n",
407-
" 20 50 \n",
408-
" 22 55 \n",
409-
"\n"
410-
]
411-
}
412-
],
413-
"source": [
414-
"x = [10,11] #[10;11] gives the same\n",
415-
"z = [2,5]\n",
416-
"printblue(\"x and z\")\n",
417-
"printmat([x z])\n",
418-
"\n",
419-
"printblue(\"x'z: \")\n",
420-
"printlnPs(x'z) #dot(x,z) gives the same\n",
421-
"\n",
422-
"printblue(\"x*z':\")\n",
423-
"printmat(x*z')"
424-
]
425-
},
426-
{
427-
"cell_type": "markdown",
428-
"metadata": {},
429-
"source": [
430-
"## Vectors: Quadratic Forms\n",
431-
"\n",
432-
"A quadratic form ($A$ is an $n \\times n$ matrix and $x$ is an $n$ vector): `x'A*x` (textbook: $x'Ax$) to get a scalar. There is also the form `dot(x,A,x)`."
433-
]
434-
},
435-
{
436-
"cell_type": "code",
437-
"execution_count": 10,
438-
"metadata": {},
439-
"outputs": [
440-
{
441-
"name": "stdout",
442-
"output_type": "stream",
443-
"text": [
444-
"\u001b[34m\u001b[1mx:\u001b[22m\u001b[39m\n",
445-
" 10 \n",
446-
" 11 \n",
447-
"\n",
448-
"\u001b[34m\u001b[1mA:\u001b[22m\u001b[39m\n",
449-
" 1 3 \n",
450-
" 3 4 \n",
451-
"\n",
452-
"\u001b[34m\u001b[1mx'A*x: \u001b[22m\u001b[39m\n",
453-
" 1244 \n"
454-
]
455-
}
456-
],
457-
"source": [
458-
"A = [1 3;3 4]\n",
459-
"x = [10,11]\n",
460-
"\n",
461-
"printblue(\"x:\")\n",
462-
"printmat(x)\n",
463-
"printblue(\"A:\")\n",
464-
"printmat(A)\n",
465-
"\n",
466-
"printblue(\"x'A*x: \")\n",
467-
"printlnPs(x'A*x) #or dot(x,A,x)"
468-
]
469-
},
470470
{
471471
"cell_type": "markdown",
472472
"metadata": {},
@@ -498,27 +498,6 @@
498498
"A[1,:]"
499499
]
500500
},
501-
{
502-
"cell_type": "code",
503-
"execution_count": 12,
504-
"metadata": {},
505-
"outputs": [
506-
{
507-
"data": {
508-
"text/plain": [
509-
"1×2 Matrix{Int64}:\n",
510-
" 1 3"
511-
]
512-
},
513-
"execution_count": 12,
514-
"metadata": {},
515-
"output_type": "execute_result"
516-
}
517-
],
518-
"source": [
519-
"A[1:1,:]"
520-
]
521-
},
522501
{
523502
"cell_type": "code",
524503
"execution_count": null,
@@ -534,15 +513,15 @@
534513
},
535514
"anaconda-cloud": {},
536515
"kernelspec": {
537-
"display_name": "Julia 1.11.1",
516+
"display_name": "Julia 1.11.3",
538517
"language": "julia",
539518
"name": "julia-1.11"
540519
},
541520
"language_info": {
542521
"file_extension": ".jl",
543522
"mimetype": "application/julia",
544523
"name": "julia",
545-
"version": "1.11.1"
524+
"version": "1.11.3"
546525
}
547526
},
548527
"nbformat": 4,

0 commit comments

Comments
 (0)