You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"2.18 Programming for Geoscientists class test - 14:00-16:00 18th December 2014\n"
17
+
]
18
+
},
19
+
{
20
+
"cell_type": "markdown",
21
+
"metadata": {},
22
+
"source": [
23
+
"#Test instructions\n",
24
+
"\n",
25
+
"* This test contains **5** questions each of which should be answered.\n",
26
+
"* Write your program in a Python cell just under each question.\n",
27
+
"* You can write an explanation of your solution as comments in your code.\n",
28
+
"* In each case your solution program must fulfil all of the instructions - please check the instructions carefully and double check that your program fulfils all of the given instructions.\n",
29
+
"* Save your work regularly.\n",
30
+
"* At the end of the test you should email your IPython notebook document (i.e. this document) to [Gerard J. Gorman](http://www.imperial.ac.uk/people/g.gorman) at g.gorman@imperial.ac.uk"
31
+
]
32
+
},
33
+
{
34
+
"cell_type": "markdown",
35
+
"metadata": {},
36
+
"source": [
37
+
"**Question 1** \n",
38
+
"\n",
39
+
"* Correct the 5 errors in the following program.\n",
40
+
"* In each case add a comment explaining the error and the fix.\n",
41
+
"* To verify your answer remember that $sin ^2( x ) + cos ^2( x ) = 1$."
42
+
]
43
+
},
44
+
{
45
+
"cell_type": "code",
46
+
"collapsed": false,
47
+
"input": [
48
+
"from math import sin, cos\n",
49
+
"x = pi /4\n",
50
+
"1_val = sin^2( x ) + cos^2( x )\n",
51
+
"print 1_VAL"
52
+
],
53
+
"language": "python",
54
+
"metadata": {},
55
+
"outputs": []
56
+
},
57
+
{
58
+
"cell_type": "markdown",
59
+
"metadata": {},
60
+
"source": [
61
+
"**Question 2**\n",
62
+
"\n",
63
+
"* Create a python list containing 101 evenly spaced values between -1.0 and 1.0.\n",
64
+
"* Show how this could be more efficently done using NumPy.\n",
65
+
"* Print out the values using a formatted print statement."
66
+
]
67
+
},
68
+
{
69
+
"cell_type": "code",
70
+
"collapsed": false,
71
+
"input": [],
72
+
"language": "python",
73
+
"metadata": {},
74
+
"outputs": []
75
+
},
76
+
{
77
+
"cell_type": "markdown",
78
+
"metadata": {},
79
+
"source": [
80
+
"**Question 3**\n",
81
+
"\n",
82
+
"* a. Write a python function that evaluates the equation below for input variables $x$ and $t$: $$f(x, t) = e^{-(x-3t)^2} \\sin \\left( 3\\pi \\left( x-t \\right) \\right)$$\n",
83
+
"* b. Generate an array of $x$ values in the range $[-3.0, 10]$.\n",
84
+
"* c. Using this array of x values, plot the function for $t=0.0$, $t=1.0$ and $t=2.0$."
85
+
]
86
+
},
87
+
{
88
+
"cell_type": "code",
89
+
"collapsed": false,
90
+
"input": [],
91
+
"language": "python",
92
+
"metadata": {},
93
+
"outputs": []
94
+
},
95
+
{
96
+
"cell_type": "markdown",
97
+
"metadata": {},
98
+
"source": [
99
+
"**Question 4**\n",
100
+
"\n",
101
+
"* Write a program to read the data file *seismic.dat* and store the magnitude of the earthquakes (*i.e.* the last column) in an numpy array.\n",
102
+
"* How many earthquakes are there above magnitude 6.0?"
103
+
]
104
+
},
105
+
{
106
+
"cell_type": "code",
107
+
"collapsed": false,
108
+
"input": [],
109
+
"language": "python",
110
+
"metadata": {},
111
+
"outputs": []
112
+
},
113
+
{
114
+
"cell_type": "markdown",
115
+
"metadata": {},
116
+
"source": [
117
+
"**Question 5** The file *human_evolution.txt* holds information about various human species and their hight, weight, and brain volume. \n",
118
+
"\n",
119
+
"* Write a program that reads this file and stores the data in a python dictionary humans.\n",
120
+
"* The dictionary key should correspond to the specie name (e.g., \u201chomo erectus\u201d), and the value should be a list containing the corresponding data. For example, humans[\"H. habilis\"] should give [\"2.2 - 1.6\", \"1.0 \u2013 1.5\", \"33 \u2013 55\", \"660\"].\n",
121
+
"* Write out the humans dictionary in a formatted tabular form."
0 commit comments