Exercise C10

In Example TMP the first table lists the cost (per kilogram) to manufacture each of the three varieties of trail mix (bulk, standard, fancy). For example, it costs $3.69 to make one kilogram of the bulk variety. Re-compute each of these three costs and notice that the computations are linear in character.

# Costs per kilogram for each ingredient
# Costs per kilogram for each ingredient
cost_raisins <- 2.55
cost_peanuts <- 4.65
cost_chocolate <- 4.80

# Mix for each 15kg batch (in kilograms)
mix_bulk <- list(raisins = 7, peanuts = 6, chocolate = 2)
mix_standard <- list(raisins = 6, peanuts = 4, chocolate = 5)
mix_fancy <- list(raisins = 2, peanuts = 5, chocolate = 8)

# Function to calculate cost per kilogram for a mix
calculate_cost_per_kg <- function(mix) {
  total_cost <- mix$raisins * cost_raisins + mix$peanuts * cost_peanuts + mix$chocolate * cost_chocolate
  cost_per_kg <- total_cost / 15  # Divide by 15kg to get cost per kilogram
  return(cost_per_kg)
}

# Calculating cost per kilogram for each variety
cost_per_kg_bulk <- calculate_cost_per_kg(mix_bulk)
cost_per_kg_standard <- calculate_cost_per_kg(mix_standard)
cost_per_kg_fancy <- calculate_cost_per_kg(mix_fancy)

# Print the costs
cost_per_kg_bulk
## [1] 3.69
cost_per_kg_standard
## [1] 3.86
cost_per_kg_fancy
## [1] 4.45

Explain Linearity: We note that this process is linear in nature because each step involves either proportional scaling (multiplying the quantity of an ingredient by its cost per kilogram) or addition (summing the cost contributions of all ingredients). These are linear operations, meaning if you were to increase the quantity of an ingredient, the total cost would increase in a directly proportional way.