using-sage/questions.rst
author anand
Mon, 15 Nov 2010 15:51:46 +0530
changeset 515 0eaf233cb64f
parent 408 8f4c369a41f1
permissions -rw-r--r--
checklist ok
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     1
Objective
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     2
---------
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
302
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
     4
1. How do you find the limit of the function ``x/sin(x)`` as ``x`` tends to
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
     5
   ``0`` from the negative side.
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
     6
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
     7
   Answer: lim(x/sin(x), x=0, dir="below")
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
     8
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
     9
#. Find the third differential of the function ``exp(sin(x)*cos(x^2))``
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    10
 
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    11
   Answer: diff(exp(sin(x)*cos(x^2), x, 3)
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    12
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    13
#. Solve the system of linear equations::
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    14
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    15
     x-2y+3z = 7
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    16
     2x+3y-z = 5
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    17
     x+2y+4z = 9
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    18
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    19
   Answer::
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    20
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    21
     A = Matrix([[1, -2, 3], 
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    22
                 [2, 3, -1], 
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    23
                 [1, 2, 4]])
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    24
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    25
     b = vector([7, 5, 9])
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    26
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    27
     solve_right(A, b)
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    28
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    29
#. How do you get the factorized form of ``x^4 - 4x^2 + x^3 + 2x + 7`` 
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    30
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    31
   Answer::
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    32
302
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    33
      factor( x^4 + x^3 - 4*x^2 + 2*x + 7 )
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    34
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    35
#. list all the primes between 2009 and 2900
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    36
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    37
   Answer: prime_range(2009, 2901)
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    38
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    39
#. Which function is used to check primality
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    40
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    41
   a. isPrime
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    42
   #. isprime
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    43
   #. is_prime
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    44
   #. prime
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    45
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    46
   Answer: is_prime
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    47
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    48
#. How do you list all the combinations of ``[1, 2, 3, 4]``
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    49
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    50
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    51
   Answer::
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    52
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    53
     c1 = Combinations([1, 2, 3, 4])
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    54
     c1.list()
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    55
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    56
#. How do you list all the permutations of ``[1, 3, 2, 3]``
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    57
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    58
    Answer::
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    59
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    60
      p1 = Permutations([1, 3, 2, 3])
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    61
      p2.list()
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    62
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    63
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    64
Programming
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    65
-----------
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    66
408
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    67
1. Obtain the sum of primes between 1 million and 2 million. 
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    68
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    69
   Answer::
302
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    70
408
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    71
     prime_sum = 0
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    72
     for i in range(1000001, 2000000, 2):
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    73
         if is_prime(i):
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    74
         prime_sum += i
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    75
        
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    76
     prime_sum
302
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    77
408
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    78
   OR
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    79
   ::
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    80
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    81
     sum(prime_range(1000000, 2000000))
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    82
408
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    83
2. ``graphs.WorldMap()`` gives the world map in the form of a
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    84
   graph. ::
302
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    85
408
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    86
       G = graphs.WorldMap()
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    87
       G.vertices()
302
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    88
408
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    89
  
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    90
   Suppose, I wish to go from India to France by Road, find out the
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    91
   least number of Visas that I'll have to obtain. 
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    92
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    93
   Answer::
302
04fc3e7a0480 added questions
Nishanth <nishanth@fossee.in>
parents: 217
diff changeset
    94
408
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    95
      G.distance("India", "France")
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    96
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    97
      
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    98
8f4c369a41f1 Changes to using sage.
Puneeth Chaganti <punchagan@fossee.in>
parents: 361
diff changeset
    99