Uploaded by Lebogang Phatlhane

MPR213 Exam Memo: Built Environment & IT

advertisement
lOMoARcPSD|32886863
MPR213 Sem Test 1 2016 Memo
Built environment and information technology (University of Pretoria)
Scan to open on Studocu
Studocu is not sponsored or endorsed by any college or university
Downloaded by Lebogang Phatlhane (phatlhanelebogang6@gmail.com)
lOMoARcPSD|32886863
Question 1
[10]
The multiple choice answers are as follows:
1.1) D
1.2) B
1.3) D
1.4) A
Bladsy 1 van 7 / Page 1 of 7
Downloaded by Lebogang Phatlhane (phatlhanelebogang6@gmail.com)
lOMoARcPSD|32886863
Question 2
[18]
"""
Fundamental Concepts (FC):
1) Generate a sequence of odd AND even numbers
- no sequence of odd AND even numbers --> missing FC1
- computing only 1 odd and even number --> missing FC1
2) Compute each term in the given sequence
- not taking care of integer division --> missing FC2
(must show float division at least once in the computation of the
sequence term)
- aditional garbage terms (Eg. multiple nested loops) --> missing FC2
3) Sum the terms in the given sequence
- no summation --> missing FC3
- summing a single scalar value --> missing FC3
Possible FC Mistakes (FCM):
1) Edge case mistake (missing the first or last odd or even number)
2) List or array sizes mismatch (1 element too long or too short)
3) Not using float division through out
Marks (Percentage):
0 - 0 fundamental concepts in place
20 - 1 fundamental concepts in place
40 - 2 fundamental concepts in place.
60 - All fundamental concepts in place.
2 or more FC implementation mistakes.
80 - All fundamental concepts in place.
1 implementation mistakes.
100 - All fundamental concepts in place.
No FC implementation mistakes.
"""
# Version 1
total = 0
for odd in range(1, 100, 2):
term = (1.0 / odd)**((odd + 1.0) / odd)
total = total + term
print total
Bladsy 2 van 7 / Page 2 of 7
Downloaded by Lebogang Phatlhane (phatlhanelebogang6@gmail.com)
lOMoARcPSD|32886863
# Version 2
total = 0
odd_numbers = range(1, 100, 2)
even_numbers = range(2, 101, 2)
for i in range(50):
odd = odd_numbers[i]
even = even_numbers[i]
term = (1.0 / odd)**(1.0 * even / odd)
total = total + term
print total
# Version 3
import numpy as np
total = 0
odd_numbers = np.arange(1.0, 100, 2.0)
even_numbers = np.arange(2.0, 101, 2.0)
terms = (1 / odd_numbers)**(even_numbers / odd_numbers)
total = np.sum(terms)
print total
The different versions of the question answers shown above are not the only solutions available, many others exist.
Bladsy 3 van 7 / Page 3 of 7
Downloaded by Lebogang Phatlhane (phatlhanelebogang6@gmail.com)
lOMoARcPSD|32886863
Question 3
[19]
"""
PART A:
------Fundamental Concepts (FC):
1) Correct import and usage of the sin function
- no / incorrect import --> missing FC1
- not giving a single scalar value input to math.sin --> missing FC1
2) Correct computation of the x AND v sequence terms
- not using the given initial sequence values --> missing FC2
- initial value are not diffined --> missing FC2
- attempting to index an empty list for the initial values -->
missing FC2
- indexing a list when the initial values are numbers (and visa
versa) --> missing FC2
- attemping operations directly on lists --> missing FC2
3) Update the x and v values for computing the next terms
- not updating for computing the next sequence terms --> missing FC3
Possible FC Mistakes (FCM):
1) Using the new x in the velocity sequence calculation (or visa
versa), For Example:
x = x + 0.1 * v
v = v - 10 * x + 0.1 * sin(0.1 * omega * (k + 1))
2) Edge case mistake (1 too many or too few values computed from the
sequences)
3) No attempt to calculate the max displacement (x3 FCM)
4) Integer division mistakes
Marks (Percentage):
0 - 0 fundamental concepts in place
20 - 1 fundamental concepts in place
40 - 2 fundamental concepts in place.
60 - All fundamental concepts in place.
2 or more FC mistakes.
80 - All fundamental concepts in place.
1 FC mistakes.
100 - All fundamental concepts in place.
Bladsy 4 van 7 / Page 4 of 7
Downloaded by Lebogang Phatlhane (phatlhanelebogang6@gmail.com)
lOMoARcPSD|32886863
No FC mistakes.
PART B:
------Fundamental Concepts (FC):
1) Repeat all of the code in Part A for the given range of \omega
values (Ie. Concept of nested loops).
2) Store the maximum displacement values in a list or array
Marks (Percentage):
0 - 1 or less fundamental concepts in place
100 - All fundamental concepts in place.
Any number of FC mistakes.
"""
# Version 1
from math import sin
max_disp = []
omega_values = range(1, 21, 1)
for omega in omega_values:
x = [0.0] * 11
v = [0.0] * 11
for k in range(10):
x[k+1] = x[k] + 0.1 * v[k]
v[k+1] = v[k] - 10 * x[k] + 0.1 * sin(0.1 * omega * (k + 1))
max_disp.append( max(x) )
# only for extra info, not part of the memo
import matplotlib.pylab as plt
plt.plot(omega_values, max_disp)
plt.show()
# Version 2
from math import sin
max_disp = []
omega_values = range(1, 21, 1)
for omega in omega_values:
x = 0
v = 0
Bladsy 5 van 7 / Page 5 of 7
Downloaded by Lebogang Phatlhane (phatlhanelebogang6@gmail.com)
lOMoARcPSD|32886863
x_vals = [x]
v_vals = [v]
for k in range(10):
x_new = x + 0.1 * v
v_new = v - 10 * x + 0.1 * sin(0.1 * omega * (k + 1))
x_vals.append(x_new)
v_vals.append(v_new)
x = x_new
v = v_new
max_disp.append( max(x_vals) )
# only for extra info, not part of the memo
import matplotlib.pylab as plt
plt.plot(omega_values, max_disp)
plt.show()
# Version 3
from math import sin
max_disp = []
omega_values = range(1, 21, 1)
for omega in omega_values:
x = 0
v = 0
max_x = x
for k in range(10):
x_new = x + 0.1 * v
v_new = v - 10 * x + 0.1 * sin(0.1 * omega * (k + 1))
max_x = max(max_x, x_new)
x = x_new
v = v_new
max_disp.append( max_x )
# only for extra info, not part of the memo
import matplotlib.pylab as plt
plt.plot(omega_values, max_disp)
plt.show()
Bladsy 6 van 7 / Page 6 of 7
Downloaded by Lebogang Phatlhane (phatlhanelebogang6@gmail.com)
lOMoARcPSD|32886863
The different versions of the question answers shown above are not the only solutions available, many others exist.
Bladsy 7 van 7 / Page 7 of 7
Downloaded by Lebogang Phatlhane (phatlhanelebogang6@gmail.com)
Download