Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Minimizing Cost

Project: new
Views: 147
Kernel: Python 3 (Anaconda)
import math
import numpy
import matplotlib.pyplot as plt
def d(r,n): return math.ceil(200*7/(r*(n+1)))
def cost(r,n): return (d(r,n)*(500+800*n))+18000*n+10000*(d(r,n)-14+abs(d(r,n)-14))/2
a1 = numpy.arange(5,16,1)
znot = [cost(5,i) for i in a1]
print(znot)
[631500.0, 580000.0, 549500.0, 544800.0, 517600.0, 521000.0, 521200.0, 518200.0, 512000.0, 524300.0, 535000.0]
d(5,11)
24
cost(5,7)
549500.0
plt.plot(a1,znot)
[<matplotlib.lines.Line2D at 0x7fa545ae7b70>]
Image in a Jupyter notebook
x = numpy.arange (4.5,5.5,.0001) y0 = [cost(i,10) for i in x] y1 = [cost(i,11) for i in x] y2 = [cost(i,12) for i in x] y3 = [cost(i,13) for i in x] y4 = [cost(i,14) for i in x] y5 = [cost(i,15) for i in x]
plt.plot(x,y1, label = '11 crews') plt.plot(x,y2, label = '12 crews') plt.plot(x,y3, label = '13 crews') plt.plot(x,y4, label = '14 crews') plt.plot(x,y5, label = '15 crews') plt.ylabel('Total Clean up Cost') plt.xlabel('Clean Up rate') plt.legend()
<matplotlib.legend.Legend at 0x7fa54565fef0>
Image in a Jupyter notebook
def costf(r,n,f): return ((d(r,n)*(500+800*n))+18000*n+f*(d(r,n)-14+abs(d(r,n)-14))/2)
hello = numpy.arange(1,20)
q=(d(5,11))
for x in range (20): l.append(cost(5,x)) z.append(x)

z = [cost(5,i) for i in l]

min(l)
512000.0
return l.index(512000.0)
print(l)
[2800000.0, 1460000.0, 1033400.0, 817000.0, 699200.0, 631500.0, 580000.0, 549500.0, 544800.0, 517600.0, 521000.0, 521200.0, 518200.0, 512000.0, 524300.0, 535000.0, 544100.0, 551600.0, 557500.0, 561800.0]
fine = numpy.arange(8000,24000)
z0= [costf(5,10,i) for i in fine] z1= [costf(5,11,i) for i in fine] z2= [costf(5,12,i) for i in fine] z3= [costf(5,13,i) for i in fine] z4= [costf(5,14,i) for i in fine] z5= [costf(5,15,i) for i in fine]
cost(5,13)
512000.0
plt.plot(fine,z0) plt.plot(fine,z1) plt.plot(fine,z2) plt.plot(fine,z3) plt.plot(fine,z4) plt.xlable('Fine') plt.ylable('total cost') plt.show()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-17-55b14854158f> in <module>() 4 plt.plot(fine,z3) 5 plt.plot(fine,z4) ----> 6 plt.xlable('Fine') 7 plt.ylable('total cost') 8 plt.show() AttributeError: module 'matplotlib.pyplot' has no attribute 'xlable'
Image in a Jupyter notebook
d(5,1)
140
d(5,2)
94
cost(5,2)
1033400.0
cost(5,1)
1460000.0
cost(5,3)
817000.0