1. LON-CAPA Logo
  2. Help
  3. Log In
 

Browsing resource, all submissions are temporary.


Optimization Problem

campire diagram Optimization problems are often encountered in Statistics and other fields (e.g. the least square prescription, maximum likelihood estimate,... etc). Here you will use R to tackle an old optimization problem — a famous problem solved by the French amateur mathematician Pierre de Fermat in the 17th century on the principle of least time. The following is a variant of the problem.

Suppose that you're camping near a river and you see a campfire that's getting out of hand in the distance. You have a bucket, but your bucket is empty. You know that you should run to the river with the bucket, get the water, and then run to the fire and put it out. Suppose that when you carry an empty bucket your running speed is 1.5 times of the running speed when the bucket is filled with water. What's the optimal path? Where along the river should you go to get the water so that you will reach the campfire as quickly as possible?

The geometry is shown in the diagram on the right. You are at a distance y1 = 1.6 units away from the river, the campfire is at a distance y2 = 5.7 units from the river. The distance between you and the campfire along the river (i.e. distance between points H and L) is s = 5.5 units. You want to choose a path YPC that minimizes that the time t it takes for you to go from Y to P and then to C. Since your speed from Y to P is 1.5 times the speed from P to C, in an appropriate unit the time taken is t = d(YP)/1.5 + d(PC). Using the Pythagorean theorem, we have and , where x is the distance between H and P. So we want to find the value of x to minimize

Here we introduce a straightforward method to solve this optimization problem. Suppose we want to find x to two decimal places. We know x must be between 0 and 5.5. We can try every number of 2 decimal places between 0 and 5.5, calculate the values of t and find the one x that minimizes t. To do this in R, first create a vector x using the command

x <- seq(0,5.5,0.01)

This is a vector of length 551. Construct another vector, t, by computing the values of time for all x using equation (1). In most other programming languages, this has to be done using a loop. With R, you can do it with one line of code by taking advantage of vectorized operations.

Note: There is obviously a better method to solve this problem than the brute-force approach introduced here. The purpose of this exercise is to practice the R commands you've learned. We will revisit this problem later in the course.

a. What is the minimum value in the vector t and the corresponding value of x? Round your answers to 2 decimal places.

Minimum value of t =

 Tries [_1]

Optimal value of x (2 decimal places) =

 Tries [_1]

b. Suppose you want to improve the accuracy of the calculation. Instead of two decimal places, you want to find x accurate to 4 decimal places. Repeat the calculation by trying numbers of 4 decimal places in the appropriate range and search for the minimum.

Optimal value of x (4 decimal places) =

 Tries [_1]