{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 2: Vector Spaces" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.1_1: Vector_Spaces_and_subspaces.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 70\n", "clear;\n", "close;\n", "clc;\n", "disp('Consider all vectors in R^2 whose components are positive or zero')\n", "disp('The subset is first Quadrant of x-y plane,the co-ordinates satisfy x>=0 and y>=0.It is not a subspace.')\n", "v=[1,1];\n", "disp(v,'If the Vector=');\n", "disp('Taking a scalar,c=-1')\n", "c=-1; //scalar\n", "disp(c*v,'c*v=') \n", "disp('It lies in third Quadrant instead of first,Hence violating the rule(ii).')\n", "//end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.1_2: Vector_Spaces_and_subspaces.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 71\n", "clear;\n", "close;\n", "clc;\n", "disp('Take vector space of 3X3 matrices')\n", "disp('One possible subspace is the set of lower triangular matrices,Another is set of symmetric matrices')\n", "disp('A+B,cA are both lower triangular if A and B are lower triangular ,and are symmetric if A and B are symmetric and Zero matrix is in both subspaces')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3_1: Linear_Independence.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 92\n", "clear;\n", "close;\n", "clc;\n", "disp('For linear independence,C1V1+C2V2+......CkVk=0')\n", "disp('If we choose V1=zero vector,then the set is linearly dependent.We may choose C1=3 and all other Ci=0;this is a non-trival solution that produces zero.')\n", "//end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3_2: Linear_Independence.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 92\n", "clear;\n", "close;\n", "clc;\n", "A=[1 3 3 2;2 6 9 5;-1 -3 3 0];\n", "disp('Given matrix:')\n", "disp(A)\n", "B=A;\n", "disp('C2->C2-3*C1')\n", "A(:,2)=A(:,2)-3*A(:,1);\n", "disp(A)\n", "disp('Here,C2=3*C1,Therefore the columns are linearly dependent.')\n", "disp('R3->R3-2*R2+5*R1')\n", "B(3,:)=B(3,:)-2*B(2,:)+5*B(1,:);\n", "disp(B)\n", "disp('Here R3=R3-2*R2+5*R1,therefore the rows are linearly dependent.')\n", "//end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3_3: Linear_Independence.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "clear;\n", "close;\n", "clc;\n", "A=[3 4 2;0 1 5;0 0 2];\n", "disp(A,'A=');\n", "disp('The columns of the triangular matrix are linearly independent,it has no zeros on the diagonal');\n", "//end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3_4: Linear_Independence.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 93\n", "clear;\n", "close;\n", "clc;\n", "disp('The columns of the nxn identity matrix are independent.')\n", "n=input('Enter n:');\n", "I=eye(n,n);\n", "disp(I,'I=');\n", "//end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3_5: Linear_Independence.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 93\n", "clear;\n", "close;\n", "clc;\n", "disp('Three columns in R2 cannot be independent.')\n", "A=[1 2 1;1 2 3];\n", "disp(A,'Given matrix:')\n", "[L,U]=lu(A);\n", "disp(U,'U=');\n", "disp('If c3 is 1 ,then back-substitution Uc=0 gives c2=-1,c1=1,With these three weights,the first column minus the second plus the third equals zero ,therefore linearly dependent.')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3_6: Linear_Independence.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 93\n", "clear;\n", "close;\n", "clc;\n", "disp('The vectors w1=(1,0,0),w2=(0,1,0),w3=(-2,0,0) span a plane (x-y plane) in R3. The first two vectors also span this plane, whereas w1 and w3 span only a line.');\n", "//end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3_7: Linear_Independence.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 93\n", "clear;\n", "close;\n", "clc;\n", "disp('The column space of A is excatly the space that is spanned by its columns.The row space is spanned by the rows.The definition is made to order.Multiplying A by any x gives a combination of columns; it is a vector Ax in the column space. The coordinate vectors e_1,....e_n coming from the identity matrix span Rn. Every vector b=(b_1.....,b_n) is a combination of those columns.In this example the weights are the components b_i themselves:b=b_1e_1+.....+b_ne_n.But the columns of other matrices also span R_.')\n", "//end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3_8: Basis_for_a_vector_space.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 93\n", "clear;\n", "close;\n", "clc;\n", "disp('Here,the vector v1 by itself is linearly independent , but it fails to span R2.The three vectors v1,v2,v3 certainly span R2, but are not independent. Any two of these vectors say v1 and v2 have both properties -they span and they are independent.So they form a basis.(A vector space does not have a unique basis)')\n", "//end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.3_9: Basis_for_a_vector_space.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 96\n", "clear;\n", "close;\n", "clc;\n", "disp('These four columns span the column space U,but they are not independent.')\n", "U=[1 3 3 2;0 0 3 1;0 0 0 0];\n", "disp(U,'U=');\n", "disp('The columns that contains pivots (here 1st & 3rd) are a basis for the column space. These columns are independent, and it is easy to see that they span the space.In fact,the column space of U is just the x-y plane withinn R3. C(U) is not the same as the column space C(A) before elimination-but the number of independent columns did not change.')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.4_1: The_four_fundamental_subspaces.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 107\n", "clear;\n", "close;\n", "clc;\n", "A=[1 2;3 6];\n", "disp(A,'A=');\n", "[m,n]=size(A);\n", "disp(m,'m=');\n", "disp(n,'n=');\n", "[v,pivot]=rref(A);\n", "r=length(pivot);\n", "disp(r,'rank=')\n", "cs=A(:,pivot);\n", "disp(cs,'Column space=');\n", "ns=kernel(A);\n", "disp(ns,'Null space=');\n", "rs=v(1:r,:)';\n", "disp(rs,'Row space=')\n", "lns=kernel(A');\n", "disp(lns,'Left null sapce=');" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.4_2: Inverse_of_a_mxn_matrix.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 108\n", "clear;\n", "close;\n", "clc;\n", "A=[4 0 0;0 5 0];\n", "disp(A,'A=');\n", "[m,n]=size(A);\n", "disp(m,'m=');\n", "disp(n,'n=')\n", "r=rank(A);\n", "disp(r,'rank=');\n", "disp('since m=r=2 ,there exists a right inverse .');\n", "C=A'*inv(A*A');\n", "disp(C,'Best right inverse=')\n", "//end" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2.5_1: Networks_and_discrete_applied_mathematics.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "//page 121\n", "clear;\n", "close;\n", "clc;\n", "disp('Applying current law A''y=f at nodes 1,2,3:')\n", "A=[-1 1 0;0 -1 1; -1 0 1;0 0 -1;-1 0 0];\n", "disp(A','A''=');\n", "C=diag(rand(5,1)); //Taking some values for the resistances.\n", "b=zeros(5,1);\n", "b(3,1)=rand(1);//Taking some value of the battery.\n", "f=zeros(3,1);\n", "f(2,1)=rand(1);//Taking some value of the current source.\n", "B=[b;f];\n", "disp('The other equation is inv(C)y+Ax=b.The block form of the two equations is:')\n", "C=[inv(C) A;A' zeros(3,3)];\n", "disp(C);\n", "X=['y1';'y2';'y3';'y4';'y5';'x1';'x2';'x3'];\n", "disp(X,'X=')\n", "X=C\B;\n", "disp(X,'X=');\n", "//end" ] } ], "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 }