|
184 | 184 | "printmat(A')"
|
185 | 185 | ]
|
186 | 186 | },
|
| 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 | + }, |
187 | 279 | {
|
188 | 280 | "cell_type": "markdown",
|
189 | 281 | "metadata": {},
|
|
206 | 298 | },
|
207 | 299 | {
|
208 | 300 | "cell_type": "code",
|
209 |
| - "execution_count": 5, |
| 301 | + "execution_count": 7, |
210 | 302 | "metadata": {
|
211 | 303 | "tags": []
|
212 | 304 | },
|
|
257 | 349 | },
|
258 | 350 | {
|
259 | 351 | "cell_type": "code",
|
260 |
| - "execution_count": 6, |
| 352 | + "execution_count": 8, |
261 | 353 | "metadata": {},
|
262 | 354 | "outputs": [
|
263 | 355 | {
|
|
302 | 394 | },
|
303 | 395 | {
|
304 | 396 | "cell_type": "code",
|
305 |
| - "execution_count": 7, |
| 397 | + "execution_count": 9, |
306 | 398 | "metadata": {},
|
307 | 399 | "outputs": [
|
308 | 400 | {
|
|
340 | 432 | },
|
341 | 433 | {
|
342 | 434 | "cell_type": "code",
|
343 |
| - "execution_count": 8, |
| 435 | + "execution_count": 10, |
344 | 436 | "metadata": {},
|
345 | 437 | "outputs": [
|
346 | 438 | {
|
|
375 | 467 | "printmat(1I[1:3,2])"
|
376 | 468 | ]
|
377 | 469 | },
|
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 |
| - }, |
470 | 470 | {
|
471 | 471 | "cell_type": "markdown",
|
472 | 472 | "metadata": {},
|
|
498 | 498 | "A[1,:]"
|
499 | 499 | ]
|
500 | 500 | },
|
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 |
| - }, |
522 | 501 | {
|
523 | 502 | "cell_type": "code",
|
524 | 503 | "execution_count": null,
|
|
534 | 513 | },
|
535 | 514 | "anaconda-cloud": {},
|
536 | 515 | "kernelspec": {
|
537 |
| - "display_name": "Julia 1.11.1", |
| 516 | + "display_name": "Julia 1.11.3", |
538 | 517 | "language": "julia",
|
539 | 518 | "name": "julia-1.11"
|
540 | 519 | },
|
541 | 520 | "language_info": {
|
542 | 521 | "file_extension": ".jl",
|
543 | 522 | "mimetype": "application/julia",
|
544 | 523 | "name": "julia",
|
545 |
| - "version": "1.11.1" |
| 524 | + "version": "1.11.3" |
546 | 525 | }
|
547 | 526 | },
|
548 | 527 | "nbformat": 4,
|
|
0 commit comments