Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: MAT 1630
Views: 232
Kernel: Python 3 (Anaconda 2019)

Exam 1 v2 Solutions

Problem 1

a)

b)

def minBusCost(m,n): cost = 24*m + 34*n if cost < 1300: return cost else: return 1300

Problem 2

a)

for x in range(51): for y in range(51): if 86*x-25*y == 16: print(x,y)
6 20

b)

[2*n for n in range(1,1567) if 1566%(2*n)==0]
[2, 6, 18, 54, 58, 174, 522, 1566]

Problem 3

a)

1200*(1+0.036/12)**(12*12)
1847.2071502050508

b)

-(4000-1200*(1+0.036/12)**(12*12))*0.036/(1-(1+0.036/12)**(12*12))/12
11.974611616707898

Problem 4

a)

def fun(n): if n == 0: return 1 else: return 2*fun(n-1) + 3
fun(16)
262141

b)

def stairs(n): if n == 1: return 1 elif n == 2: return 1 elif n == 3: return 2 elif n == 4: return 4 else: return stairs(n-4)+stairs(n-3)+stairs(n-1)
stairs(18)
3025

Problem 5

def bisection(a,b,f,err): c = (a+b)/2 while c-a > err: if f(c) == 0: return n elif f(c)*f(a) > 0: a = c else: b = c c = (a+b)/2 return c

a)

def p(x): return x**3-5*x+5
bisection(-3,-2,p,0.01)
-2.6328125

b)

import math def gPrime(x): return math.exp(x)-1/x
bisection(0.25,3,gPrime,0.01)
0.56689453125

Problem 6

def sevenCounter(arr): if len(arr) == 1: if arr[0] == 7: return 1 else: return 0 else: if arr[0] == 7: return 1 + sevenCounter(arr[1:]) else: return sevenCounter(arr[1:])