using-sage.rst
changeset 149 b9ae88095ade
parent 144 476ea1730aee
child 196 966be1a847c9
equal deleted inserted replaced
148:60a4616dbf55 149:b9ae88095ade
       
     1 ========
       
     2  Script
       
     3 ========
       
     4 
       
     5 {{{ show the welcome slide }}}
       
     6 
       
     7 Welcome to this tutorial on using Sage.
       
     8 
       
     9 {{{ show the slide with outline }}} 
       
    10 
       
    11 In this tutorial we shall quickly look at a few examples of the areas
       
    12 (name the areas, here) in which Sage can be used and how it can be
       
    13 used.
       
    14 
       
    15 {{{ show the slide with Calculus outline }}} 
       
    16 
       
    17 Let us begin with Calculus. We shall be looking at limits,
       
    18 differentiation, integration, and Taylor polynomial.
       
    19 
       
    20 {{{ show sage notebook }}}
       
    21 
       
    22 We have our Sage notebook running. In case, you don't have it running,
       
    23 start is using the command, ``sage --notebook``.
       
    24 
       
    25 To find the limit of the function x*sin(1/x), at x=0, we say::
       
    26 
       
    27    lim(x*sin(1/x), x=0)
       
    28 
       
    29 We get the limit to be 0, as expected. 
       
    30 
       
    31 It is also possible to the limit at a point from one direction. For
       
    32 example, let us find the limit of 1/x at x=0, when approaching from
       
    33 the positive side.::
       
    34 
       
    35     lim(1/x, x=0, dir='above')
       
    36 
       
    37 To find the limit from the negative side, we say,::
       
    38 
       
    39     lim(1/x, x=0, dir='above')   
       
    40 
       
    41 Let us now see how to differentiate, using Sage. We shall find the
       
    42 differential of the expression ``exp(sin(x^2))/x`` w.r.t ``x``. We
       
    43 shall first define the expression, and then use the ``diff`` function
       
    44 to obtain the differential of the expression.::
       
    45 
       
    46     var('x')
       
    47     f = exp(sin(x^2))/x
       
    48 
       
    49     diff(f, x)
       
    50 
       
    51 We can also obtain the partial differentiation of an expression w.r.t
       
    52 one of the variables. Let us differentiate the expression
       
    53 ``exp(sin(y - x^2))/x`` w.r.t x and y.::
       
    54 
       
    55     var('x y')
       
    56     f = exp(sin(y - x^2))/x
       
    57 
       
    58     diff(f, x)
       
    59 
       
    60     diff(f, y)
       
    61 
       
    62 Now, let us look at integration. We shall use the expression obtained
       
    63 from the differentiation that we did before, ``diff(f, y)`` ---
       
    64 ``e^(sin(-x^2 + y))*cos(-x^2 + y)/x``. The ``integrate`` command is
       
    65 used to obtain the integral of an expression or function.::
       
    66 
       
    67     integrate(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y)
       
    68 
       
    69 We get back the correct expression. The minus sign being inside or
       
    70 outside the ``sin`` function doesn't change much. 
       
    71 
       
    72 Now, let us find the value of the integral between the limits 0 and
       
    73 pi/2. ::
       
    74 
       
    75     integral(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y, 0, pi/2)
       
    76 
       
    77 Let us now see how to obtain the Taylor expansion of an expression
       
    78 using sage. Let us obtain the Taylor expansion of ``(x + 1)^n`` up to
       
    79 degree 4 about 0.::
       
    80 
       
    81     var('x n')
       
    82     taylor((x+1)^n, x, 0, 4)
       
    83 
       
    84 This brings us to the end of the features of Sage for Calculus, that
       
    85 we will be looking at. For more, look at the Calculus quick-ref from
       
    86 the Sage Wiki. 
       
    87 
       
    88 Next let us move on to Matrix Algebra. 
       
    89 
       
    90 {{{ show the equation on the slides }}}
       
    91 
       
    92 Let us begin with solving the equation ``Ax = v``, where A is the
       
    93 matrix ``matrix([[1,2],[3,4]])`` and v is the vector
       
    94 ``vector([1,2])``. 
       
    95 
       
    96 To solve the equation, ``Ax = v`` we simply say::
       
    97 
       
    98     x = solve_right(A, v)
       
    99 
       
   100 To solve the equation, ``xA = v`` we simply say::
       
   101 
       
   102     x = solve_left(A, v)
       
   103 
       
   104 The left and right here, denote the position of ``A``, relative to x. 
       
   105 
       
   106 
       
   107 
       
   108 Now, let us look at Graph Theory in Sage. 
       
   109 
       
   110 Graph: G = Graph({0:[1,2,3], 2:[4]})
       
   111 Directed Graph: DiGraph(dictionary)
       
   112 Graph families: graphs. tab
       
   113 Invariants: G.chromatic polynomial(), G.is planar()
       
   114 Paths: G.shortest path()
       
   115 Visualize: G.plot(), G.plot3d()
       
   116 Automorphisms: G.automorphism group(), G1.is isomorphic(G2), G1.is subgraph(G2)
       
   117 
       
   118 Now let us look at bits and pieces of Number theory, combinatorics, 
       
   119