{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 7: Linear Algebra" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.1: Orthonomal_basis.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ " // PG (470)\n", "u1 = [1/2,sqrt(3)/2]\n", "u2 = [-sqrt(3)/2,1/2]\n", "// For a given vector x = (x1,x2), it can be written as\n", "// x = alpha1*u1 + alpha2*u2\n", "// alpha1 = (x1+x2*sqrt(3))/2\n", "// alpha2 = (x2-x1*sqrt(3))/2\n", "// (1,0) = (1/2)*u1 - (sqrt(3)/2)*u2" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.2: Canonical_forms.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ " // PG (476)\n", "A = [0.2 0.6 0;1.6 -0.2 0;-1.6 1.2 3.0]\n", "U = [0.6 0 -0.8;0.8 0 0.6;0 1.0 0]\n", "Ustar = inv(U)\n", "T = Ustar*A*U\n", "trace(A)\n", "lam =spec(A)'\n", "lam1 = lam(1,1)\n", "lam2 = lam(1,2)\n", "lam3 = lam(1,3)\n", "lam1 + lam2 + lam3\n", " // trace(A) = lam1 + lam2 + lam3\n", "det(A)\n", "lam1*lam2*lam3\n", " // det(A) = lam1 * lam2 * lam3" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.3: Orthonomal_eigen_vectors.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ " // PG (477)\n", "A = [2 1 0;1 3 1;0 1 2]\n", "lam = spec(A)'\n", "lam1 = lam(1,1)\n", "lam2 = lam(1,2)\n", "lam3 = lam(1,3)\n", "// Orthonomal Eigen vectors\n", "u1 = (1/sqrt(3))*[1;-1;1]\n", "u2 = (1/sqrt(2))*[1;0;-1]\n", "u3 = (1/sqrt(6))*[1;2;1]" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.4: Vector_and_matrix_norms.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ " // PG (481)\n", "x = [1,0,-1,2]\n", " // 1-norm\n", "norm(x,1)\n", " // 2-norm\n", "norm(x,2)\n", " // infinity norm\n", "norm(x,'inf')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.5: Frobenious_norm.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ " // PG (484)\n", "// A be n * n \n", "// norm(A*x,2)\n", "// norm(A*x,2) <= norm(A,'fro') * norm(x,2)\n", "// norm(A*B,'fro') = norm(A,'fro') * norm(B,'fro')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.6: Norm.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ " // PG (489)\n", "A = [1 -2;-3 4]\n", "norm(A,1)\n", "norm(A,2)\n", "norm(A,'inf')\n", "lam = spec(A)\n", "r = max(abs(lam))\n", " //r < = norm(A,2)" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7.7: Inverse_exists.sce" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ " // PG (494)\n", "A = [4 1 0 0;1 4 1 0;0 1 4 1;0 0 1 4]\n", "B = A/4 - eye()\n", "norm(B,'inf')\n", " // Let (I+B = C)\n", "C = eye() + B\n", "inv(C)\n", "// Inverse of (I + B) exists\n", "norm(C,'inf')\n", "// Inverse of A exists." ] } ], "metadata": { "kernelspec": { "display_name": "Scilab", "language": "scilab", "name": "scilab" }, "language_info": { "file_extension": ".sce", "help_links": [ { "text": "MetaKernel Magics", "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" } ], "mimetype": "text/x-octave", "name": "scilab", "version": "0.7.1" } }, "nbformat": 4, "nbformat_minor": 0 }