{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 5: Vectors and Matrices" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5.10: Determinants.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "A=[5 4;2 3];\n", "det(A); \n", "disp(det(A),'determinant of A')\n", "B=[2 1;-4 6]\n", "det(B);\n", "disp(det(B),'determinant of B')\n", "C=[2 1 3;4 6 -1;5 1 0]\n", "disp(det(C),'determinant of C')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5.13: Matrix_solution_of_a_system_of_linear_equations.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "A=[1 2 1;2 5 -1;3 -2 -1]; //left hand side of the system of equations\n", "B=[3 -4 5]'; //right hand side or the constants in the equations\n", "X=[];\n", "X=A\B ; //unique solution for the system of equations\n", "x=X(1)\n", "y=X(2)\n", "z=X(3)" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5.14: Inverse_of_a_square_matrix.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "A=[1 0 2;2 -1 3;4 1 8];\n", "P=rref([A,eye(3,3)]);\n", "disp(P,'canonical form of matrix A :')\n", "disp('left side of the matrix P is the identity matrix so the right side is the inverse of A') \n", "inverseA=P(:,4:6) " ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5.2: Vector_operations.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "u=[2,3,-4];\n", "v=[1,-5,8];\n", "u+v\n", "5*u\n", "-v\n", "2*u-3*v\n", "u.*v;\n", "k=sum(u.*v);\n", "disp(k,'dot product of the two vectors')\n", "l=norm(u); \n", "disp(l,'norm or length of the vector u')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5.3: Column_vectors.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "u=[5,3,-4]'\n", "v=[3,-1,-2]'\n", "2*u-3*v\n", "k=sum(u.*v);\n", "disp(k,'The dot product of the two vectors u and v is:')\n", "l=norm(u);\n", "disp(l,'The length or norm of the vector u is:')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5.5: Matrix_addition_and_Scalar_multiplication.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "A=[1,-2,3;0,4,5];\n", "B=[4,6,8;1,-3,-7];\n", "k=A+B;\n", "disp(k,'The addition of the two matrices A and B is:')\n", "m=3*A;\n", "disp(m,'The multiplication of a vector with a scalar is:')\n", "p=2*A-3*B" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5.6: Matrix_multiplicatio.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "a=[7,-4,5];\n", "b=[3,2,-1]';\n", "k=a*b;\n", "disp(k,'product of a and b is;')\n", "p=[6,-1,8,3];\n", "q=[4,-9,-2,5]';\n", "l=p*q;\n", "disp(l,'product of p and q is:')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5.7: Matrix_multiplicatio.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "A=[1 3;2 -1];\n", "B=[2 0 -4;5 -2 6];\n", "A*B\n", "A=[1 2;3 4]\n", "B=[5 6;0 -2];\n", "A*B\n", "B*A\n", "disp('matrix mulitplication is not commutative since AB may not be equal to BA')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5.8: Algebra_of_square_matrices.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "A=[1 2;3 -4];\n", "A2=A*A //multiplying A by itself\n", "A3=A2*A\n", "f=2*A2-3*A+5; \n", "disp(f,'for the function f(x)=2x^2-3x+5,f(A) is:')\n", "g=A2+3*A-10;\n", "disp(g,'for the function g(x)=x^2+3x-10,g(A) is')" ] } , { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5.9: Invertible_matrices.sci" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "A=[1 0 2;2 -1 3;4 1 8];\n", "B=[-11 2 2;-4 0 1;6 -1 -1];\n", "A*B\n", "disp('since A*B is identity matrix,A and B are invertible and inverse of each other')" ] } ], "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 }