Page 251, Question #2. 

Nutritional Requirements – A rancher has determined that the minimum weekly nutritional requirements for an average-sized horse include 40lb of protein, 20lb of carbohydrates, and 45lb of roughage. These are obtained from the following sources in varying amounts at the prices indicated:

Protein (lb) Carbs (lb) Roughage (lb) Cost
Hay (per bale) 0.5 2.0 5.0 $1.80
Oats (per sack) 1.0 4.0 2.0 $3.50
Feeding Blocks (per block) 2.0 0.5 1.0 $0.40
High Protein Concentrate (per sack) 6.0 1.0 2.5 $1.00
Requirements per horse (per week) 40.0 20.0 45.0

Let’s \(x_1\) = the amount of Hay per bale
Let’s \(x_2\) = the amount of the amount of Oats per sack
Let’s \(x_3\) = the amount of Feeding Blocks (per block)
Let’s \(x_4\) = the amount of High Protein Concentrate (per sack)
Since each unit of cost of (Hay, Oats, Feeding Blocks, High Protein Concentrate) is (1.8, 3.5, 0.4, 1.0), then the total cost in dollars is:\[C= 1.8x_1 + 3.5x_2+0.4x_3+x_4\] which is what we want to minimize.

Next, we need to consider the minimum requirement amount of protein.

\[0.5x_1+x_2+2x_3+6x_4 >= 40\]

Next, we need to consider the minimum requirement amount of carbohydrates.

\[2x_1+4x_2+0.5x_3+x_4 >= 20\]

Next, we need to consider the minimum requirement amount of Roughage.

\[5x_1+2x_2+x_3+2.5x_4 >= 45\]

Hence the mathematical model that will help us determine how to meet the minimum nutrition requirements at minimum cost is as follow:

\[ minimize \qquad C= 1.8x_1 + 3.5x_2+0.4x_3+x_4\]

subject to: \[0.5x_1+x_2+2x_3+6x_4 >= 40\] \[2x_1+4x_2+0.5x_3+x_4 >= 20\] \[5x_1+2x_2+x_3+2.5x_4 >= 45\] where \[ x_1, x_2,x_3,x_4 >= 0\]

Page 264, Question 6

Minimize 10x + 35y

subject to:

\[ 8x + 6y \leq 48 \quad (Board-feet \ of \ lumber)\] \[ 4x + y \leq 20 \quad (hours \ of \ carpentry)\] \[ y \geq 5 \quad (demand)\] \[ x, y \geq 0 \quad ( nonnegativity) \]

Now let’s plot the main constraints

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.2.3
library(reshape2)
x <- seq(0,10,by=0.5)

lumber= 8- (4/3) *x
labor = 20 - 4*x
demand = 5

data1 <- data.frame(x = x, lumber, labor, demand )
data2 <- melt(data1, id.vars="x", value.name="y")
ggplot(data2, aes(x=x, y=y, color=variable)) + geom_line()

Now lets find the convex set for the constraints

plot(c(0, 10), c(0, 20), type='n')
abline(8, -4/3)
abline(20,-4)
abline(5,0 )


conditions <- function(x,y) {
  c1 <- (y <= 8 -  x * (4/3))
  c2 <- (y <= 20 - 4*x )
  c3 <- (y >=  5)
  return(c1 & c2 & c3 )
}

x <- seq(0,10,length=1000)
y <- seq(0,20,length=1000)
z <- expand.grid(x=x,y=y)
z <- z[conditions(z$x,z$y),]
points(z, col="red")

From the graph, the area colored in red shows three extreme points: (0,5), (0,8), and (2.4,5).
Hence for:
- (0,5) the objective function value is: 175
- (0,8) the objective function value is: 280
- (2.4, 5) the objective function value is: 199
Therefore, the maximum value happens when x = 0 and y = 8

Page 268, Question 6 Algebraic method

Minimize 10x + 35y

subject to:

\[ 8x + 6y \leq 48 \quad (Board-feet \ of \ lumber)\] \[ 4x + y \leq 20 \quad (hours \ of \ carpentry)\] \[ y \geq 5 \quad (demand)\] \[ x, y \geq 0 \quad ( nonnegativity) \]

Page 268, Answer 6 Algebraic method

First we need to add slack \(r_i\) and surplus \(s_i\) variable accordingly.
Hence our systemof equation will be as follow:

\[ 8x + 6y + r_1 = 48 \quad (Board-feet \ of \ lumber)\] \[ 4x + y + r_2 = 20 \quad (hours \ of \ carpentry)\] \[ y - s_1 = 5 \quad (demand)\] \[ x, y, r_1, r_2, s_1 \geq 0 \quad ( nonnegativity) \]

1- let’s begin by assigning x and y to zero. our system becomes:

\[ 0 + 0 + r_1 = 48 \quad (Board-feet \ of \ lumber)\] \[ 0 + 0 + r_2 = 20 \quad (hours \ of \ carpentry)\] \[ 0 - s_1 = 5 \quad (demand)\] \[ x, y, r_1, r_2, s_1 \geq 0 \quad ( nonnegativity) \]

We get \(r_1 = 48,\)  \(r_2= 20,\)  \(s_1 = -5\)
Since \(s_1\) is less than zero, then x = 0 and y = 0 is not in feasible vertex.

2- Next we assign x= 0 and \(r_1=0\), our system becomes:
\[ 0 + 6y + 0 = 48 \quad (Board-feet \ of \ lumber)\] \[ 0 + y + r_2 = 20 \quad (hours \ of \ carpentry)\] \[ y - s_1 = 5 \quad (demand)\] \[ x, y, r_1, r_2, s_1 \geq 0 \quad ( nonnegativity) \]

We get, y = 8, \(r_2\)= 12, and \(s_1\)=3. since all variable are greater than zero, the point call it A=(x=0, y=8) is in feasible vertex. \(\qquad point: A\)

3- Next we assign x = 0 and \(r_2 =0\), our system becomes:
\[ 0 + 6y + r_1 = 48 \quad (Board-feet \ of \ lumber)\] \[ 0 + y + 0 = 20 \quad (hours \ of \ carpentry)\] \[ y - s_1 = 5 \quad (demand)\] \[ x, y, r_1, r_2, s_1 \geq 0 \quad ( nonnegativity) \]

We get, y = 20, \(s_1=-15\), and x =-72. since \(s_1\) and x ar eless than zero, then the point x,y is not in feasible vertex.

4- Next we assign \(r_1 = 0\) and \(r_2 =0\), our system becomes:
\[ 8x + 6y + 0 = 48 \quad (Board-feet \ of \ lumber)\] \[ 4x + y + 0 = 20 \quad (hours \ of \ carpentry)\] \[ y - s_1 = 5 \quad (demand)\] \[ x, y, r_1, r_2, s_1 \geq 0 \quad ( nonnegativity) \]

we get, y = 2, and \(s_1=-3\) since \(s_2\) is less than zero, then the point x,y is not in feasible vertex.

5- Next we assign \(r_1 = 0\) and \(s_1 =0\), our system becomes:
\[ 8x + 6y + 0 = 48 \quad (Board-feet \ of \ lumber)\] \[ 4x + y + r_2 = 20 \quad (hours \ of \ carpentry)\] \[ y - 0 = 5 \quad (demand)\] \[ x, y, r_1, r_2, s_1 \geq 0 \quad ( nonnegativity) \]

we get y = 5, x = 9/4, and \(r_2=6\). since all variable are greater than zero, then point call it B(x=9/4,y=5) is in feasible vertex. \(\qquad point: B\)

6- Next we assign \(r_2 = 0\) and \(s_1 =0\), our system becomes:
\[ 8x + 6y + r_1 = 48 \quad (Board-feet \ of \ lumber)\] \[ 4x + y + 0 = 20 \quad (hours \ of \ carpentry)\] \[ y - 0 = 5 \quad (demand)\] \[ x, y, r_1, r_2, s_1 \geq 0 \quad ( nonnegativity) \]

we get y = 5, x = 15/4, and \(r_1=-12\). since \(r_1\) is less than zero, then the point x,y is not in feasible vertex.

7- next we Next we assign x = 0 and \(s_1 =0\), our system becomes:
\[ 0 + 6y + r_1 = 48 \quad (Board-feet \ of \ lumber)\] \[ 0 + y + r_2 = 20 \quad (hours \ of \ carpentry)\] \[ y - 0 = 5 \quad (demand)\] \[ x, y, r_1, r_2, s_1 \geq 0 \quad ( nonnegativity) \] we get y = 5, \(r_2= 15\) , and \(r_1=18\). Since all variable are greater than zero, the point call it C(x=0,y=5) is in feasible vertex. \(\qquad point: C\)

Now, let’s find the cost function value at points:
- A(0,8) the objective function value is: 280
- B(2.4, 5) the objective function value is: 199
- C(0,5) the objective function value is: 175
Therefore, the maximum value happens at point A, when x = 0 and y = 8

Page_278_6_simplex<- readLines("C:/CUNY/Courses/IS609/Assignment609/Assignment06/simplex-289_99_3.txt", n=-1)

Page_278_6_simplex
##   [1] "The initial system is found by converting the inequality constraints into equality constraints by adding a slack variable:"                                                
##   [2] ""                                                                                                                                                                          
##   [3] "Maximize P = 10 x + 35y + 0s_1 + 0 s_2 + 0 s_3 subject to:"                                                                                                                
##   [4] "8 x + 6y + 1s_1 = 48"                                                                                                                                                      
##   [5] "4 x + 1 y + 1s_2 = 20"                                                                                                                                                     
##   [6] "0 x + 1 y -1s_3 = 5"                                                                                                                                                       
##   [7] "x, y, s_1, s_2, s_3, ? 0"                                                                                                                                                  
##   [8] " "                                                                                                                                                                         
##   [9] "Tableau 0"                                                                                                                                                                 
##  [10] "X     y      s1           s2         s3       P          RHS             Ratio"                                                                                            
##  [11] "8     6       1            0           0        0          48              48/6 = 8"                                                                                       
##  [12] "4     1       0            1           0        0          20               20/1= 20"                                                                                      
##  [13] "0     1       0            0          -1        0           5               5/1=5"                                                                                         
##  [14] "-10   -35     0            0           0          1         0"                                                                                                             
##  [15] ""                                                                                                                                                                          
##  [16] ""                                                                                                                                                                          
##  [17] "We have to move the smallest distance possible to stay within the feasible region. The pivot row is the row that has the smallest non-negative ratio. Row #3, with pivot 1"
##  [18] "Hence, entries for pivot row (Row 3):"                                                                                                                                     
##  [19] "5 / 1 = 5"                                                                                                                                                                 
##  [20] "0 / 1 = 0"                                                                                                                                                                 
##  [21] "1 / 1 = 1"                                                                                                                                                                 
##  [22] "0 / 1 = 0"                                                                                                                                                                 
##  [23] "0 / 1 = 0"                                                                                                                                                                 
##  [24] "-1 / 1 = -1"                                                                                                                                                               
##  [25] "1 / 1 = 1"                                                                                                                                                                 
##  [26] ""                                                                                                                                                                          
##  [27] ""                                                                                                                                                                          
##  [28] "Row 1:"                                                                                                                                                                    
##  [29] "48 - (6 * 5) = 18"                                                                                                                                                         
##  [30] "8 - (6 * 0) = 8"                                                                                                                                                           
##  [31] "6 - (6 * 1) = 0"                                                                                                                                                           
##  [32] "1 - (6 * 0) = 1"                                                                                                                                                           
##  [33] "0 - (6 * 0) = 0"                                                                                                                                                           
##  [34] "0 - (6 * -1) = 6"                                                                                                                                                          
##  [35] "0 - (6 * 1) = -6"                                                                                                                                                          
##  [36] ""                                                                                                                                                                          
##  [37] "Row 2:"                                                                                                                                                                    
##  [38] "20 - (1 * 5) = 15"                                                                                                                                                         
##  [39] "4 - (1 * 0) = 4"                                                                                                                                                           
##  [40] "1 - (1 * 1) = 0"                                                                                                                                                           
##  [41] "0 - (1 * 0) = 0"                                                                                                                                                           
##  [42] "1 - (1 * 0) = 1"                                                                                                                                                           
##  [43] "0 - (1 * -1) = 1"                                                                                                                                                          
##  [44] "0 - (1 * 1) = -1"                                                                                                                                                          
##  [45] ""                                                                                                                                                                          
##  [46] "Calculate the Z line:"                                                                                                                                                     
##  [47] "(0) + (0 * 18) + (0 * 15) + (-35 * 5) = -175"                                                                                                                              
##  [48] "(10) + (0 * 8) + (0 * 4) + (-35 * 0) = 10"                                                                                                                                 
##  [49] "(35) + (0 * 0) + (0 * 0) + (-35 * 1) = 0"                                                                                                                                  
##  [50] "(0) + (0 * 1) + (0 * 0) + (-35 * 0) = 0"                                                                                                                                   
##  [51] "(0) + (0 * 0) + (0 * 1) + (-35 * 0) = 0"                                                                                                                                   
##  [52] "(0) + (0 * 6) + (0 * 1) + (-35 * -1) = 35"                                                                                                                                 
##  [53] ""                                                                                                                                                                          
##  [54] ""                                                                                                                                                                          
##  [55] ""                                                                                                                                                                          
##  [56] ""                                                                                                                                                                          
##  [57] ""                                                                                                                                                                          
##  [58] ""                                                                                                                                                                          
##  [59] "Tableau 1"                                                                                                                                                                 
##  [60] "x         y          s1          s2         s3        P          RHS        Ratio"                                                                                         
##  [61] "8        0           1            0          6        0           18          18/6 = 3"                                                                                    
##  [62] "4        0           0            1          1         0          15          15/1= 15"                                                                                    
##  [63] "0        1          0            0          -1          0         5           5/1=5"                                                                                       
##  [64] "-10     0           0             0         -35        1           -175"                                                                                                   
##  [65] ""                                                                                                                                                                          
##  [66] ""                                                                                                                                                                          
##  [67] ""                                                                                                                                                                          
##  [68] ""                                                                                                                                                                          
##  [69] ""                                                                                                                                                                          
##  [70] "Pivot row (Row 1):"                                                                                                                                                        
##  [71] "18 / 6 = 3"                                                                                                                                                                
##  [72] "8 / 6 = 1.3333333333333"                                                                                                                                                   
##  [73] "0 / 6 = 0"                                                                                                                                                                 
##  [74] "1 / 6 = 0.16666666666667"                                                                                                                                                  
##  [75] "0 / 6 = 0"                                                                                                                                                                 
##  [76] "6 / 6 = 1"                                                                                                                                                                 
##  [77] ""                                                                                                                                                                          
##  [78] ""                                                                                                                                                                          
##  [79] "Row 2:"                                                                                                                                                                    
##  [80] "15 - (1 * 3) = 12"                                                                                                                                                         
##  [81] "4 - (1 * 1.3333333333333) = 2.6666666666667"                                                                                                                               
##  [82] "0 - (1 * 0) = 0"                                                                                                                                                           
##  [83] "0 - (1 * 0.16666666666667) = -0.16666666666667"                                                                                                                            
##  [84] "1 - (1 * 0) = 1"                                                                                                                                                           
##  [85] "1 - (1 * 1) = 0"                                                                                                                                                           
##  [86] ""                                                                                                                                                                          
##  [87] ""                                                                                                                                                                          
##  [88] ""                                                                                                                                                                          
##  [89] ""                                                                                                                                                                          
##  [90] "Row 3:"                                                                                                                                                                    
##  [91] "5 - (-1 * 3) = 8"                                                                                                                                                          
##  [92] "0 - (-1 * 1.3333333333333) = 1.3333333333333"                                                                                                                              
##  [93] "1 - (-1 * 0) = 1"                                                                                                                                                          
##  [94] "0 - (-1 * 0.16666666666667) = 0.16666666666667"                                                                                                                            
##  [95] "0 - (-1 * 0) = 0"                                                                                                                                                          
##  [96] "-1 - (-1 * 1) = 0"                                                                                                                                                         
##  [97] ""                                                                                                                                                                          
##  [98] ""                                                                                                                                                                          
##  [99] "Row Z:"                                                                                                                                                                    
## [100] "175 - (-35 * 3) = 280"                                                                                                                                                     
## [101] "-10 - (-35 * 1.3333333333333) = 36.666666666667"                                                                                                                           
## [102] "0 - (-35 * 0) = 0"                                                                                                                                                         
## [103] "0 - (-35 * 0.16666666666667) = 5.8333333333333"                                                                                                                            
## [104] "0 - (-35 * 0) = 0"                                                                                                                                                         
## [105] "-35 - (-35 * 1) = 0"                                                                                                                                                       
## [106] ""                                                                                                                                                                          
## [107] "Tableau 2"                                                                                                                                                                 
## [108] "x          y            s1       s2      s3       P       RHS"                                                                                                             
## [109] "4/3       0           1/6        0        1        0         3"                                                                                                            
## [110] "4          0           -1/6      1         0       0         12"                                                                                                           
## [111] "4/3        1            1/6       0        0       0         8"                                                                                                            
## [112] "116/3     0            35/6        0       0       1         280"                                                                                                          
## [113] ""                                                                                                                                                                          
## [114] ""                                                                                                                                                                          
## [115] ""                                                                                                                                                                          
## [116] "As we can see there are no more negative coefficients in the last row. Hence, we have reached the "                                                                        
## [117] "The optimal solution value is Z = 280  at:"                                                                                                                                
## [118] "Independent variables x = 0 and s_1 = 0.  "                                                                                                                                
## [119] ""                                                                                                                                                                          
## [120] "Hence replacing s_1=0 in 8x + 6y +s_1 = 48,  we get 6y=48, hence y = 8. "                                                                                                  
## [121] "Therefore, the optimal solution value is Z = 280"                                                                                                                          
## [122] "X1 = 0"                                                                                                                                                                    
## [123] "X2 = 8"                                                                                                                                                                    
## [124] ""                                                                                                                                                                          
## [125] ""

Page 295, question 3

Use the Curve Fitting Criterion to minimize the sum of the absolute deviations for the following models and data set:

  1. \(y = ax\)

  2. \(y = ax^2\)

  3. \(y = ax^3\)

Page 295, Answer 3

Model \(y = ax\)

1- first define the interval a and b. i ll chos eteh interval 0, 50 2- set r = .618 and define th etest points x1 and x2 x1= a + ( 1- r)(b -a) x2 = a + r(b-a)

we wil find the function to be minimized
f(x) = abs(8 - 7c) + abs(41 - 14c) + abs(133 - 21c) + abs(250 - 28c) + abs(280 - 35c) + abs(297 - 42c)

x <- c(7,14,21,28,35,42)
y <- c(8,41,133,250,280,297)
df1 <- data.frame(x=x, y=y)
a<- 0
b<- 50

r<- ((1+sqrt(5))/2)-1
c1 = a + (1 - r)*(b - a)
c2 = a + r*(b -a)

cost <- function(a, df){
  sum(abs(df$y - a*(df$x)))
}

f_c1<- cost(c1,df1)
f_c2<- cost(c2,df1)

table1 <- data.frame(a=a,b=b,c1=c1,c2=c2,f_c1=f_c1,f_c2=f_c2)

t <- 0.02
d <- 1
while(d > t){
  if(f_c1<=f_c2){
    b <- c2
    c1 <- a+(1-r)*(b-a)
    c2 <- a+r*(b-a)
    f_c1 <- cost(c1,df1)
    f_c2 <- cost(c2,df1)
    table1 <- rbind(table1,c(a,b,c1,c2,f_c1,f_c2))
    d <- b-a
  } else{
    a <- c1
    c1 <- a+(1-r)*(b-a)
    c2 <- a+r*(b-a)
    f_c1 <- cost(c1,df1)
    f_c2 <- cost(c2,df1)
    table1 <- rbind(table1,c(a,b,c1,c2,f_c1,f_c2))
    d <- b-a
  }
}

table1
##           a         b        c1        c2      f_c1      f_c2
## 1  0.000000 50.000000 19.098301 30.901699 1798.4502 3533.5498
## 2  0.000000 30.901699 11.803399 19.098301  726.0996 1798.4502
## 3  0.000000 19.098301  7.294902 11.803399  204.1929  726.0996
## 4  0.000000 11.803399  4.508497  7.294902  437.6078  204.1929
## 5  4.508497 11.803399  7.294902  9.016994  204.1929  316.4982
## 6  4.508497  9.016994  6.230590  7.294902  256.7881  204.1929
## 7  6.230590  9.016994  7.294902  7.952683  204.1929  218.0063
## 8  6.230590  7.952683  6.888371  7.294902  211.0326  204.1929
## 9  6.888371  7.952683  7.294902  7.546152  204.1929  209.4692
## 10 6.888371  7.546152  7.139621  7.294902  200.9320  204.1929
## 11 6.888371  7.294902  7.043652  7.139621  201.2499  200.9320
## 12 7.043652  7.294902  7.139621  7.198933  200.9320  202.1776
## 13 7.043652  7.198933  7.102964  7.139621  200.1622  200.9320
## 14 7.043652  7.139621  7.080309  7.102964  199.6865  200.1622
## 15 7.043652  7.102964  7.066307  7.080309  199.8227  199.6865
## 16 7.066307  7.102964  7.080309  7.088962  199.6865  199.8682
## 17 7.066307  7.088962  7.074960  7.080309  199.5742  199.6865
## 18 7.066307  7.080309  7.071655  7.074960  199.5048  199.5742
l<- length(table1$a)
table1$a[l] 
## [1] 7.066307
table1$b[l]
## [1] 7.080309
c1_optimal <- (table1$a[l]+ table1$b[l] ) /2
c1_optimal
## [1] 7.073308
f_c1_optimal<- cost(c1_optimal,df1)
f_c1_optimal
## [1] 199.5395
##############

Model \(y = ax^2\)

We wil find the function to be minimized:
f(x) = abs(8 - 7^2 c) + abs(41 - 14^2 c) + abs(133 - 21^2 * c) + 250 - 28^2 c) + abs(280 - 35^2 c) + abs(297 - 42^2 *c)

x <- c(7,14,21,28,35,42)
y <- c(8,41,133,250,280,297)
df2 <- data.frame(x=x, y=y, x2=x^2)

a<- 0
b<- 50
r<- ((1+sqrt(5))/2)-1
c1 = a + (1 - r)*(b - a)
c2 = a + r*(b -a)

cost2 <- function(a, df){
  sum(abs(df$y - a*(df$x2) ))
}


f_c1<- cost2(c1,df2)
f_c2<- cost2(c2,df2)

table2 <- data.frame(a=a,b=b,c1=c1,c2=c2,f_c1=f_c1,f_c2=f_c2)


t <- 0.02
d <- 1
while(d > t){
  if(f_c1<=f_c2){
    b <- c2
    c1 <- a+(1-r)*(b-a)
    c2 <- a+r*(b-a)
    f_c1 <- cost2(c1,df2)
    f_c2 <- cost2(c2,df2)
    table2 <- rbind(table2,c(a,b,c1,c2,f_c1,f_c2))
    d <- b-a
  } else{
    a <- c1
    c1 <- a+(1-r)*(b-a)
    c2 <- a+r*(b-a)
    f_c1 <- cost2(c1,df2)
    f_c2 <- cost2(c2,df2)
    table2 <- rbind(table2,c(a,b,c1,c2,f_c1,f_c2))
    d <- b-a
  }
}

l<- length(table2$a)
table2$a[l] 
## [1] 0.2232466
table2$b[l]
## [1] 0.2372483
c2_optimal <- (table2$a[l]+ table2$b[l] ) /2
c2_optimal
## [1] 0.2302474
f_c2_optimal<- cost2(c2_optimal,df2)
f_c2_optimal
## [1] 219.5671
##############

Model \(y = ax^3\)

We wil find the function to be minimized:
f(x) = abs(8 - 7^3 c) + abs(41 - 14^3 c) + abs(133 - 21^3 * c) + 250 - 28^3 c) + abs(280 - 35^3 c) + abs(297 - 42^3 *c)

x <- c(7,14,21,28,35,42)
y <- c(8,41,133,250,280,297)
df3 <- data.frame(x=x, y=y, x3=x^3)

a<- 0
b<- 50
r<- ((1+sqrt(5))/2)-1
c1 = a + (1 - r)*(b - a)
c2 = a + r*(b -a)

cost3 <- function(a, df){
  sum(abs(df$y - a*(df$x3)))
}


f_c1<- cost3(c1,df3)
f_c2<- cost3(c2,df3)

table3 <- data.frame(a=a,b=b,c1=c1,c2=c2,f_c1=f_c1,f_c2=f_c2)


t <- 0.02
d <- 1
while(d > t){
  if(f_c1<=f_c2){
    b <- c2
    c1 <- a+(1-r)*(b-a)
    c2 <- a+r*(b-a)
    f_c1 <- cost3(c1,df3)
    f_c2 <- cost3(c2,df3)
    table3 <- rbind(table3,c(a,b,c1,c2,f_c1,f_c2))
    d <- b-a
  } else{
    a <- c1
    c1 <- a+(1-r)*(b-a)
    c2 <- a+r*(b-a)
    f_c1 <- cost3(c1,df3)
    f_c2 <- cost3(c2,df3)
    table3 <- rbind(table3,c(a,b,c1,c2,f_c1,f_c2))
    d <- b-a
  }
}

l<- length(table3$a)
table3$a[l] 
## [1] 0
table3$b[l]
## [1] 0.01400168
c3_optimal <- (table3$a[l]+ table3$b[l] ) /2
c3_optimal
## [1] 0.00700084
cost3(c3_optimal,df3)
## [1] 433.7104
##############