# HG changeset patch # User Nishanth # Date 1286860648 -19800 # Node ID efb8ddf26aff372797bbdb97a0de55c8ab83e3e5 # Parent 5c8e88276e1f6ec54b5edadd44eb665a0b8b6dee Finished lstsq diff -r 5c8e88276e1f -r efb8ddf26aff lstsq/questions.rst --- a/lstsq/questions.rst Tue Oct 12 10:36:46 2010 +0530 +++ b/lstsq/questions.rst Tue Oct 12 10:47:28 2010 +0530 @@ -8,6 +8,8 @@ #. [1.0, 1.0, 1.0] #. Error + Answer: array([1, 1, 1]) + 2. What does ones_like([1.2, 3, 4, 5]) produce a. [1.2, 3, 4, 5] @@ -15,4 +17,16 @@ #. array([1, 1, 1, 1]) #. array([1.2, 3, 4, 5]) + Answer: array([1.0, 1.0, 1.0, 1.0]) + 3. The plot of ``u`` vs ``v`` is a bunch of scattered points that show a + linear trend. How do you find the least square fit line of ``u`` vs ``v``. + + Answer:: + + A = array(u, ones_like(u)).T + result = lstsq(A, v) + m, c = result[0] + + lst_line = m * u + c + diff -r 5c8e88276e1f -r efb8ddf26aff lstsq/quickref.tex --- a/lstsq/quickref.tex Tue Oct 12 10:36:46 2010 +0530 +++ b/lstsq/quickref.tex Tue Oct 12 10:47:28 2010 +0530 @@ -1,11 +1,15 @@ -Creating a tuple:\\ -{\ex \lstinline| t = (1, "hello", 2.5)|} +Creating a matrix with all ones:\\ +{\ex \lstinline| o = ones_like(l)|} -Accessing elements of tuples:\\ -{\ex \lstinline| t[index] Ex: t[2]|} +Creating the A matrix:\\ +{\ex \lstinline| A = array(l, ones_like(l)).T|} -Accessing slices of tuples:\\ -{\ex \lstinline| t[start:stop:step]|} +Computing least square:\\ +{\ex \lstinline| result = lstsq(A, tsq)|} -Swapping values:\\ -{\ex \lstinline| a, b = b, a|} +Obtaining the m and c values:\\ +{\ex \lstinline| m, c = result[0]|} + +Computing the least square fit line:\\ +{\ex \lstinline| lst_line = m * l + c|} + diff -r 5c8e88276e1f -r efb8ddf26aff lstsq/script.rst --- a/lstsq/script.rst Tue Oct 12 10:36:46 2010 +0530 +++ b/lstsq/script.rst Tue Oct 12 10:47:28 2010 +0530 @@ -1,11 +1,6 @@ .. Objectives .. ---------- -.. A - Students and teachers from Science and engineering backgrounds - B - - C - - D - - .. Plotting a least square fit line .. Prerequisites @@ -13,6 +8,7 @@ .. 1. Basic Plotting .. 2. Arrays +.. 3. Loading data from files .. Author : Nishanth Amuluru Internal Reviewer :