A product’s demand price is \(P(x) = 50 - 2x\) dollars. Revenue is \(R(x) = x \space p(x)\) for \(0 < x < 25\). Which \(x\) maximizes revenue?
A. 12.5
B. 25
C. 0
D. 10
E. 15
Revenue <- function(x) {
-(x * (50 - 2 * x)) # negative sign for maximization, positive sigh for minimization
}
optimization_result <- optim(par = 10, # parameter: usually middle of interval
fn = Revenue, # function: function to maximize/minimize
method = "Brent", # method: Brent method for this problem
lower = 0, # lower: lower part of the interval
upper = 25) # upper: upper part of the interval
cat("The x that maximizes revenue is:",optimization_result$par,"\n")
## The x that maximizes revenue is: 12.5
We find that answer choice A 12.5 is correct.
Solve the following system of equations.
\[x + y + z = 1 \\ 2x + 3y + 2z = 3 \\ x + 2y + 5z = 2\]
q2_data <- data.frame(X = c(1,2,1),
Y = c(1,3,2),
Z = c(1,2,5),
Constants = c(1,3,2))
q2_model <- lm(Constants ~ . - 1,data = q2_data) # "." means all other variables except response variable, -1 to exclude intercept
coef(q2_model)
## X Y Z
## 0 1 0
Which one of the following is NOT a factor of 220?
A. 4
B. 10
C. 11
D. 12
# install.packages("tidyverse")
library(tidyverse)
## Warning: package 'lubridate' was built under R version 4.5.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.2
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
q3_data <- data.frame(Choice = LETTERS[1:4],
Factor = c(4,10,11,12),
Number = rep(220,4))
correct_answer <- q3_data %>%
mutate(Correct = Number %% Factor == 0) %>%
filter(Correct == FALSE) %>%
pull(Choice)
cat("The correct answer is:",correct_answer,"\n")
## The correct answer is: D
Plot the corresponding polygon with the given data below.
# install.packages("tidyverse")
library(tidyverse)
q4_data <- data.frame(x = c(5,-3,-3,5),
y = c(4,4,-4,-4))
ggplot(q4_data,aes(x = x,y = y)) +
geom_polygon(fill = "steelblue",col = "black",lwd = 1.5) +
geom_point(size = 4) +
coord_equal() +
theme_gray()