Difference between revisions of "CompSciHW5"

From Predictive Chemistry
Jump to: navigation, search
(Created page with "Homework 6 - Due Friday, March 4, 2016 <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 = """ # ti...")
 
Line 1: Line 1:
Homework 6 - Due Friday, March 4, 2016
+
Homework 5 - Due Friday, March 4, 2016
 
<pre>
 
<pre>
1) Create a function that parses the following files:
+
1) Use numpy and pyplot to plot the following functions:
a) mat33 = """
+
(remember to start by choosing an appropriate range for x)
1.0 2.0 3.0
+
a) f(x) = sin(x) cos(2x)
-2.0 0.0 1.0
+
b) g(x) = x (if x is in 0,1), 2-x (if x is in 1,2), 0 otherwise
1.0 1.1 1.2
+
c) h(x) = exp(-x*x/(2*sigma)), for sigma = 1, 2, and 3
"""
+
d) w(x) = g(x) - 4*g(x-2.0)
   
b) csv = """
 
  +
2) Name the type of the following functions:
# time temperature sea_level
 
  +
(remember that *a means a list is input and **a means a dictionary)
0.0, 300.0, 44.5
 
  +
a) def joinwith(space, *a):
1.5, 299.5, 44.0
 
  +
return space.join(a)
3.0, 299.8, 44.2
 
  +
b) def map_on_n(f, n):
4.5, 301.0, 43.9
 
  +
return [f(i) for i in range(n)]
"""
 
  +
c) def get_elem(k="default", **d):
 
  +
return d[k] + 2.0
c) name_val = """
 
  +
d) def chaos(*a, **b):
seed = 1553
 
  +
return random.random()*random.random()
name = "test name"
 
trials = 10
 
tolerance = 1e-8
 
"""
 
 
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
 
"""
 
 
2) Write code to carry out matrix multiplication manually
 
and test it against the result of numpy.dot.
 
 
3) Write code to multiply every column of matrix, A,
 
with every other column. Use this to find the set of angles
 
between the column vectors.
 
 
</pre>
 
</pre>

Revision as of 14:55, 19 February 2016

Homework 5 - Due Friday, March 4, 2016

1) Use numpy and pyplot to plot the following functions:
    (remember to start by choosing an appropriate range for x)
 a) f(x) = sin(x) cos(2x)
 b) g(x) = x (if x is in 0,1), 2-x (if x is in 1,2), 0 otherwise
 c) h(x) = exp(-x*x/(2*sigma)), for sigma = 1, 2, and 3
 d) w(x) = g(x) - 4*g(x-2.0)

2) Name the type of the following functions:
   (remember that *a means a list is input and **a means a dictionary)
 a) def joinwith(space, *a):
        return space.join(a)
 b) def map_on_n(f, n):
        return [f(i) for i in range(n)]
 c) def get_elem(k="default", **d):
        return d[k] + 2.0
 d) def chaos(*a, **b):
        return random.random()*random.random()