Initial work
This commit is contained in:
52
CS1029/practical-2023-10-20/functions
Normal file
52
CS1029/practical-2023-10-20/functions
Normal file
@@ -0,0 +1,52 @@
|
||||
1. a) f(x) is undefined for x = 0
|
||||
b) f(x) is complex for x < 0
|
||||
c) multivalued
|
||||
|
||||
2. a) multivalued
|
||||
b) It is
|
||||
c) undefined at x = 2
|
||||
|
||||
3. a) Z >= 0, {0..9}
|
||||
b) 0.. -> 1..?
|
||||
c) All bit strings -> N
|
||||
d) All bit strings -> N
|
||||
e) (Z^+)^2 -> Z^+
|
||||
f) (Z^+)^2 -> Z^+
|
||||
|
||||
4. a) 1 b) 2 c) -1 d) 0 e) 2 f) 3 g) 0 h) 2
|
||||
5. a) 1 b) 0 c) 0 d) -1 e) 3 f) -1 g) 2 h) 1
|
||||
|
||||
8. a) 6 b) 24 c) 120 d) 3_628_800
|
||||
|
||||
10. a)y b)n c)n
|
||||
11. {a}
|
||||
|
||||
12. a) y b) n c) n d) n
|
||||
13. a) y b) n) c) y) d) n
|
||||
|
||||
14. ynyy
|
||||
|
||||
15. a) everyone has a phone number (phone numbers should already be uniquie)
|
||||
b) None (student ids should already be unique)
|
||||
c) Every student gets a unique grade
|
||||
d) no two people come from the same town
|
||||
|
||||
16. a) the set of phone numbers
|
||||
b) the set of student ids
|
||||
c) 1..100
|
||||
d) all towns
|
||||
|
||||
17. ynnn
|
||||
18. a) { 1 }
|
||||
b) { -1, 1, 5, 9, 15 }
|
||||
c) { 0, 1, 2 }
|
||||
d) { 0, 1, 2 }
|
||||
|
||||
19. f.g = x^2 + 4x + 5, g.f = x^2 + 3
|
||||
20. f + g = x^2 + x + 3
|
||||
fg = x^3 + 2x^2 + x + 2
|
||||
|
||||
21. f^-1 doesn't exist, assuming f^-1(x) = +sqrt(x)
|
||||
a) { 1 }
|
||||
b) { x | 0 < x < 1 }
|
||||
c) { x | x > 2 }
|
||||
22
CS1029/practical-2023-10-20/m.py
Normal file
22
CS1029/practical-2023-10-20/m.py
Normal file
@@ -0,0 +1,22 @@
|
||||
def floor(n):
|
||||
return n - (n % 1)
|
||||
|
||||
def ceil(n):
|
||||
return n - (n % -1)
|
||||
|
||||
|
||||
assert floor(-1) == -1
|
||||
assert floor(1) == 1
|
||||
assert floor(1.2) == 1
|
||||
assert floor(-1.2) == -2
|
||||
assert floor(0) == 0
|
||||
assert floor(0.1) == 0
|
||||
assert floor(-0.1) == -1
|
||||
assert ceil(-1) == -1
|
||||
assert ceil(1) == 1
|
||||
assert ceil(1.2) == 2
|
||||
assert ceil(-1.2) == -1
|
||||
assert ceil(0) == 0
|
||||
assert ceil(0.1) == 1
|
||||
assert ceil(-0.1) == 0
|
||||
|
||||
35
CS1029/practical-2023-10-20/sequences
Normal file
35
CS1029/practical-2023-10-20/sequences
Normal file
@@ -0,0 +1,35 @@
|
||||
1. a) 3
|
||||
b) -1
|
||||
c) 787
|
||||
d) 2639
|
||||
|
||||
2. a) 128
|
||||
b) 7
|
||||
c) 2
|
||||
d) -256
|
||||
|
||||
3. a) 1, -2, 4, -8
|
||||
b) 3, 3, 3, 3
|
||||
c) 8, 13, 23, 71
|
||||
d) 2, 0, 8, 0
|
||||
|
||||
4. a) 2, 5, 8, 11, 14, 17, 20, 23, 26, 29
|
||||
b) 0, 0, 0, 1, 1, 1, 2, 2, 2, 3
|
||||
c) 1, 1, 3, 3, 5, 5, 7, 7, 9, 9
|
||||
d) 3, 6, 12, 24, 48, 96, 192, 384, 768, 1336
|
||||
|
||||
5. a_0 = 3, a_n = a_{n - 1} + 2 (i.e. the odd integers starting at 3)
|
||||
the primes starting at three
|
||||
- one more
|
||||
|
||||
6. a) 2, 12, 72, 432, 2592
|
||||
b) 2, 4, 16, 256, 65536
|
||||
c) 1, 2, 5, 11, 26
|
||||
d) 1, 1, 6, 27, 204
|
||||
|
||||
7. a) a_n = -3a_{n-1} + 4a_{n-2} = -3(0) + 4(0) = 0 = a_n
|
||||
b) a_n = -3(1) + 4(1) = 4 - 3 = 1 = a_n
|
||||
c) a_n = -3((-4)^{n-1}) + 4((-4)^{n-2}) = -3(-4)(-4^{n-2}) + 4((-4)^{n-2}) = (-4)^{n-2}((-3)(-4) + 4) = (-4)^{n-1}(-3 - 1) = (-4)^n = a_n
|
||||
d) a_n = -3(2*(-4)^{n-1} + 3) + 4(2 * (-4)^{n-2} + 3) = -6(-4)^{n-1} - 9 - 2(-4)^{n-1} + 12 = -8(-4)^{n-1} + 3 = 2(-4)^n + 3 = a_n
|
||||
|
||||
8.
|
||||
Reference in New Issue
Block a user