```{r fig.width=7, fig.height=7}
visualize(simdat, xvar = "price", yvar = "profit", type = "line")
```

## Finding the optimal price for Iceskimo

### Setup the simulation


```{r}
simdat <- simulater(sequ = "price 0 12;", form = "## What is the optimal price for Iceskimo?;sales = 100 - 10 * price;profit = sales * (price - 2);## We could also use the profit function directly;profit_fun = -10*price^2 + 120*price - 200;## Use the find_max function to find the price that maximizes profits;optimal_price = find_max(profit, price);optimal_price_fun = find_max(profit_fun, price)", seed = 1234, nr = 1300)
register("simdat")
summary(simdat, dec = 2)
```

As you can see from the simulation results, the optimal price is \$6.00

### Visualize the results

```{r fig.width=7, fig.height=7}
visualize(simdat, xvar = "price", yvar = "profit", type = "line")
```

```{r fig.width = 6.46, fig.height = 6.46, dpi = 200}
visualize(
  simdat, 
  xvar = "price", 
  yvar = "profit", 
  type = "line", 
  custom = FALSE
)
```


You would get the same result if you use the profit function directly

```{r fig.width=7, fig.height=7}
visualize(simdat, xvar = "price", yvar = "profit_fun", type = "line")
```

```{r fig.width = 6.46, fig.height = 6.46, dpi = 200}
visualize(
  simdat, 
  xvar = "price", 
  yvar = "profit_", 
  type = "line", 
  custom = FALSE
)
```

## What is the optimal price for Iceskimo?
## We could also use the profit function directly
profit_fun = -10*price^2 + 120*price - 200
## Use the find_max function to find the price that maximizes profits

### Simulated data

Formula:

## What is the optimal price for Iceskimo?

sales = 100 - 10 \* price

profit = sales \* (price - 2)

#####We could also use the profit function directly

profit_fun = -10\*price^2 + 120\*price - 200

#####Use the find_max function to find the price that maximizes profits

optimal_price = find_max(profit, price)

optimal_price_fun = find_max(profit_fun, price)

Date: 2018-04-20 16:56:12