Difference between revisions of "CompSciHW6"

From Predictive Chemistry
Jump to: navigation, search
(Created page with "Homework 6 - Due Friday, March 18 <pre> 1) Create a function that parses the following files: a) mat33 = """ 1.0 2.0 3.0 -2.0 0.0 1.0 1.0 1.1 1.2 """ b) csv = """ # time te...")
 
Line 1: Line 1:
Homework 6 - Due Friday, March 18
+
Homework 6 - Due Friday, March 25
 
<pre>
 
<pre>
 
1) Create a function that parses the following files:
 
1) Create a function that parses the following files:
Line 6: Line 6:
 
-2.0 0.0 1.0
 
-2.0 0.0 1.0
 
1.0 1.1 1.2
 
1.0 1.1 1.2
"""
 
  +
""" # output a matrix
   
 
b) csv = """
 
b) csv = """
Line 14: Line 14:
 
3.0, 299.8, 44.2
 
3.0, 299.8, 44.2
 
4.5, 301.0, 43.9
 
4.5, 301.0, 43.9
"""
 
  +
""" # output a list of strings and a matrix
   
 
c) name_val = """
 
c) name_val = """
Line 21: Line 21:
 
trials = 10
 
trials = 10
 
tolerance = 1e-8
 
tolerance = 1e-8
"""
 
  +
""" # output a dictionary
   
 
d) group_data = """
 
d) group_data = """
Line 32: Line 32:
 
[Group 3]
 
[Group 3]
 
7 8 9 10 11
 
7 8 9 10 11
"""
 
  +
""" # output a dictionary of [int]
   
2) Write code to carry out matrix multiplication manually
 
  +
2) Complete this function by adding a for loop to fill each
and test it against the result of numpy.dot.
 
  +
element of a vector with a function (g(i)):
  +
from numpy import *
  +
def vec_from_func(n, g): # int -> (int -> float) -> array
  +
x = zeros(n, float)
  +
for ...
  +
return x
  +
g_arr =
   
3) Write code to multiply every column of matrix, A,
 
  +
3) Complete this function by adding a nested for-loop to fill
with every other column. Use this to find the set of angles
 
  +
each element of a matrix with a function, u(i,j):
between the column vectors.
 
  +
from numpy import *
  +
def mat_from_func(n,m, g): # int -> int -> (int -> int -> float) -> array
  +
M = zeros((n,m), float)
  +
for ...
  +
for ...
  +
return M
 
</pre>
 
</pre>

Revision as of 09:41, 21 March 2016

Homework 6 - Due Friday, March 25

1) Create a function that parses the following files:
 a) mat33 = """
1.0 2.0 3.0
-2.0 0.0 1.0
1.0 1.1 1.2
""" # output a matrix

 b) csv = """
# time temperature sea_level
0.0, 300.0, 44.5
1.5, 299.5, 44.0
3.0, 299.8, 44.2
4.5, 301.0, 43.9
""" # output a list of strings and a matrix

 c) name_val = """
seed = 1553
name = "test name"
trials = 10
tolerance = 1e-8
""" # output a dictionary

 d) group_data = """
[Group 1]
1 2 3 4 5 6

[Group 2]
4 5 11 14 1

[Group 3]
7 8 9 10 11
""" # output a dictionary of [int]

2) Complete this function by adding a for loop to fill each 
  element of a vector with a function (g(i)):
  from numpy import *
  def vec_from_func(n, g): # int -> (int -> float) -> array
    x = zeros(n, float)
    for ...
    return x
  g_arr =

3) Complete this function by adding a nested for-loop to fill
   each element of a matrix with a function, u(i,j):
   from numpy import *
   def mat_from_func(n,m, g): # int -> int -> (int -> int -> float) -> array
   M = zeros((n,m), float)
   for ...
     for ...
   return M