plotting_using_sage/questions.rst
changeset 262 0038edaf660c
parent 255 75fd106303dc
equal deleted inserted replaced
256:a3aa223c1662 262:0038edaf660c
     1 Objective Questions
     1 Objective Questions
     2 -------------------
     2 -------------------
     3 
     3 
     4  1. If ``a = [1, 1, 2, 3, 3, 5, 5, 8]``. What is set(a)
     4  1. Plot the curve ``sin(x) - cos(x)`` in the range (0, 2pi)
     5 
       
     6    a. set([1, 1, 2, 3, 3, 5, 5, 8])
       
     7    #. set([1, 2, 3, 5, 8])
       
     8    #. set([1, 2, 3, 3, 5, 5])
       
     9    #. Error
       
    10 
       
    11    Answer: set([1, 2, 3, 5, 8])
       
    12 
       
    13  2. ``a = set([1, 3, 5])``. How do you find the length of a?
       
    14 
       
    15    Answer: len(a)
       
    16 
       
    17  3. ``a = set([1, 3, 5])``. What does a[2] produce?
       
    18 
       
    19    a. 1
       
    20    #. 3
       
    21    #. 5
       
    22    #. Error
       
    23 
       
    24    Answer: Error
       
    25 
       
    26  4. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
       
    27     is the value of ``odd | squares``?
       
    28 
       
    29    Answer: set([1, 3, 4, 5, 7, 9, 16])
       
    30 
       
    31  5. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
       
    32     is the value of ``odd - squares``?
       
    33 
       
    34    Answer: set([3, 5, 7])
       
    35 
       
    36  6. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
       
    37     is the value of ``odd ^ squares``?
       
    38 
       
    39    Answer: set([3, 4, 5, 7, 16])
       
    40 
       
    41  7. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
       
    42     does ``odd * squares`` give?
       
    43 
       
    44    a. set([1, 12, 45, 112, 9])
       
    45    #. set([1, 3, 4, 5, 7, 9, 16])
       
    46    #. set([])
       
    47    #. Error
       
    48 
       
    49    Answer: Error
       
    50 
       
    51  8. ``a = set([1, 2, 3, 4])`` and ``b = set([5, 6, 7, 8])``. What is ``a + b``
       
    52 
       
    53    a. set([1, 2, 3, 4, 5, 6, 7, 8])
       
    54    #. set([6, 8, 10, 12])
       
    55    #. set([5, 12, 21, 32])
       
    56    #. Error
       
    57 
       
    58  9. ``a`` is a set. how do you check if if a varaible ``b`` exists in ``a``?
       
    59 
       
    60    Answer: b in a
       
    61 
       
    62  10. ``a`` and ``b`` are two sets. What is ``a ^ b == (a - b) | (b - a)``?
       
    63 
       
    64    a. True
       
    65    #. False
       
    66 
       
    67    Answer: False
       
    68 
       
    69 
       
    70 Larger Questions
       
    71 ----------------
       
    72 
       
    73  1. Given that mat_marks is a list of maths marks of a class. Find out the
       
    74     no.of duplicates marks in the list.
       
    75 
     5 
    76    Answer::
     6    Answer::
    77 
     7 
    78      unique_marks = set(mat_marks)
     8        x = var('x')
    79      no_of_duplicates = len(mat_marks) - len(unique_marks)
     9        plot(sin(x) - cos(x), (x, 0, 2*pi))
    80 
    10 
    81  2. Given that mat_marks is a list of maths marks of a class. Find how many
    11  2. plot ``sin(3x)`` and ``cos(x/3)`` and show them in same figure
    82     duplicates of each mark exist.
       
    83 
    12 
    84    Answer::
    13    Answer::
    85 
    14 
    86      marks_set = set(mat_marks)
    15        x = var('x')
    87      for mark in marks_set:
    16        p1 = plot(sin(3*x), (x, 0, 2*pi))
    88          occurences = mat_marks.count(mark)
    17        p2 = plot(cos(x/3), (x, 0, 2*pi))
    89          print occurences - 1, "duplicates of", mark, "exist"
    18        show(p1+p2)
    90 
    19 
       
    20  3. plot ``cos(x)`` vs ``sin(x)^15`` in the range (-2pi, 2pi)
       
    21 
       
    22    Answer::
       
    23 
       
    24        x = var('x')
       
    25        parametric_plot((cos(x), sin(x)^15), (x, -2*pi, 2*pi))
       
    26 
       
    27  4. plot tan curve in the range (-2pi, 2pi) in red colour.
       
    28     [hint: see the documentation]
       
    29 
       
    30    Answer::
       
    31 
       
    32        x = var('x')
       
    33        p1 = plot(tan(x), (x, -2*pi, 2*pi), color=(1, 0, 0))
       
    34        show(p1)
       
    35 
       
    36  5. plot ``e^(1/x^2)`` in the range (0.5, 2.5) and set the y-axis limits to (0,
       
    37     20)
       
    38 
       
    39    Answer::
       
    40 
       
    41        x = var('x')
       
    42        p2 = plot(e^(1/x^2), (x, 0.5, 2.5))
       
    43        show(p2, ymin=0, ymax=20)
       
    44 
       
    45  6. plot the function ``y = 5x + 3`` using dotted line in the range (-2, 2)
       
    46     [hint: read the documentation of the function ``line``]
       
    47 
       
    48    Answer::
       
    49 
       
    50        points = [ (i, 5*i+3) for i in srange(-2,2,0.1) ]
       
    51        l1 = line(points, linestyle=":")
       
    52        show(l1)
       
    53 
       
    54  7. plot the function ``z = cos(x) + sin(y)`` for x in the range (0, 2pi) and y
       
    55     in range (-2pi, 2pi)
       
    56 
       
    57    Answer::
       
    58 
       
    59        x, y = var('x y')
       
    60        plot3d(cos(x) + sin(y), (x, 0, 2*pi), (y, -2*pi, 2*pi))
       
    61 
       
    62  8. Read the sage documentation and find out which function plots closed surfaces
       
    63 
       
    64    a. parametric_plot3d
       
    65    #. plot3d
       
    66    #. implicit_plot3d
       
    67    #. contour_plot
       
    68 
       
    69    Answer: implicit_plot3d
       
    70