lstsq/questions.rst
author anand
Mon, 15 Nov 2010 14:31:42 +0530
changeset 498 4255f995a40c
parent 330 efb8ddf26aff
permissions -rw-r--r--
checklist not OK; one more long answer question has to be included.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
237
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     1
Objective Questions
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     2
-------------------
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     3
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     4
 1. What does ones_like([1, 2, 3]) produce
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     5
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     6
   a. array([1, 1, 1])
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     7
   #. [1, 1, 1]
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     8
   #. [1.0, 1.0, 1.0]
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
     9
   #. Error
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    10
   
330
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    11
   Answer: array([1, 1, 1])
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    12
   
237
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    13
 2. What does ones_like([1.2, 3, 4, 5]) produce
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    14
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    15
   a. [1.2, 3, 4, 5]
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    16
   #. array([1.0, 1.0, 1.0, 1.0])
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    17
   #. array([1, 1, 1, 1])
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    18
   #. array([1.2, 3, 4, 5])
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    19
330
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    20
   Answer: array([1.0, 1.0, 1.0, 1.0])
237
6c203780bfbe Converted lstsq to new template form
Nishanth <nishanth@fossee.in>
parents:
diff changeset
    21
330
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    22
 3. The plot of ``u`` vs ``v`` is a bunch of scattered points that show a
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    23
    linear trend. How do you find the least square fit line of ``u`` vs ``v``.
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    24
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    25
   Answer::
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    26
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    27
      A = array(u, ones_like(u)).T
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    28
      result = lstsq(A, v)
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    29
      m, c = result[0]
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    30
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    31
      lst_line = m * u + c
efb8ddf26aff Finished lstsq
Nishanth <nishanth@fossee.in>
parents: 237
diff changeset
    32