using-sage/questions.rst
author Puneeth Chaganti <punchagan@fossee.in>
Thu, 11 Nov 2010 02:55:20 +0530
changeset 459 68c324a9981c
parent 408 8f4c369a41f1
permissions -rw-r--r--
Reviewed using sage to teach

Objective
---------

1. How do you find the limit of the function ``x/sin(x)`` as ``x`` tends to
   ``0`` from the negative side.

   Answer: lim(x/sin(x), x=0, dir="below")

#. Find the third differential of the function ``exp(sin(x)*cos(x^2))``
 
   Answer: diff(exp(sin(x)*cos(x^2), x, 3)

#. Solve the system of linear equations::

     x-2y+3z = 7
     2x+3y-z = 5
     x+2y+4z = 9

   Answer::

     A = Matrix([[1, -2, 3], 
                 [2, 3, -1], 
                 [1, 2, 4]])

     b = vector([7, 5, 9])

     solve_right(A, b)

#. How do you get the factorized form of ``x^4 - 4x^2 + x^3 + 2x + 7`` 

   Answer::

      factor( x^4 + x^3 - 4*x^2 + 2*x + 7 )

#. list all the primes between 2009 and 2900

   Answer: prime_range(2009, 2901)

#. Which function is used to check primality

   a. isPrime
   #. isprime
   #. is_prime
   #. prime

   Answer: is_prime

#. How do you list all the combinations of ``[1, 2, 3, 4]``


   Answer::

     c1 = Combinations([1, 2, 3, 4])
     c1.list()

#. How do you list all the permutations of ``[1, 3, 2, 3]``

    Answer::

      p1 = Permutations([1, 3, 2, 3])
      p2.list()


Programming
-----------

1. Obtain the sum of primes between 1 million and 2 million. 

   Answer::

     prime_sum = 0
     for i in range(1000001, 2000000, 2):
         if is_prime(i):
         prime_sum += i
        
     prime_sum

   OR
   ::

     sum(prime_range(1000000, 2000000))

2. ``graphs.WorldMap()`` gives the world map in the form of a
   graph. ::

       G = graphs.WorldMap()
       G.vertices()

  
   Suppose, I wish to go from India to France by Road, find out the
   least number of Visas that I'll have to obtain. 

   Answer::

      G.distance("India", "France")