Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 5222
# Mini project: Geometric median # Your are a postmaster for a district in some state. There are n towns along a straight road. Let x[j], j=0..n-1,be the locations of the towns along the road. Your job is to determine the best location for a new post office; it should be located in one of the towns. Assume that the best location is the one that minimizes the average distance between the post office and the towns. #Follow the plan in Lecture 6 or design your own plan. Enumerate the steps of your solution.
#Template for Step 2.Plotting the objective function (the sum of the distances to the post office) is similar to Exercise 4 in the problem set for this chapter. def sum_of_dist(L): n=len(L) intervals=[(x,L[j],L[j+1]) for j in range(0,10,)] G=Graphics() #Make and plot linear pieces using the formula for objective function for k in range(1,n): piece=(?)*x+sum(L[j] for j in range(0,10sum(L[j] for j in range(?)) piece_plot=plot(?,intervals[k-1],thickness=2) G+=piece_plot G.show(figsize=[4,3]) S=[1,3,6,7,8,10];sum_of_dist(S)
############################# # Mini project: Analysis of a function f(x)=x/(x+1)-cos(40/x) with many characteristic features #Step 1 (manual) #Domain= # Complete the line # lim_(x->infinity)=0 lim_(x->-infinity)=0
#Step 2:Plot the function f(x)=x/(x+1)-cos(40/x) p=plot(f(x),-4,10,ymin=-10,ymax=10);p.show(figsize=[5,4])
#Step 3. Find the smallest negative and the largest positive x-intercepts for this function. (Note that the large intercept is REALLY large) #the smallest negative p=plot(f(x),-0.5,-0.4);p.show(figsize=[5,4])
find_root(f(x),-0.48,-0.47)
-0.4740729100063728
#THE largest positive p=plot(f(x),800.7,800.9);p.show(figsize=[5,4])
find_root(f(x),100,1000)
800.8324463325995
#Step 4 (read Lecture 4, answer the question on Step 4) No, we cannot due to the fact that there are numerous solutions.
#Step 5. Find the largest local minimum on the interval (-infinity,-1). deriv_plot=plot(derivative(f(x),x),-1.35,-1);deriv_plot.show(figsize=[5,4],ymin=-20,ymax=50) print "Largest local minimum: " find_root(derivative(f(x),x),-1.35,-1)
Largest local minimum: -1.294057347382484