Question 1

A utility function is \(U(x) = (\ln(3x + 2))^2\). What is \(U'(x)\)?

# install.packages("Deriv")
library(Deriv)
U <- function(x) {
  (log(3 * x + 2))^2
}
U_prime <- Deriv(U)
U_prime
## function (x) 
## {
##     .e1 <- 2 + 3 * x
##     6 * (log(.e1)/.e1)
## }

Question 2

If \(x = 4\) and \(y = 3\), what is the value of \(x^2 - xy\)?

expr <- function(x,y) {
  x^2 - x * y
}
value <- expr(x = 4,y = 3)
cat("The value is:",value,"\n")
## The value is: 4

Question 3

Construct a bar graph with the data frame below.

# 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(Number_of_Letters = 1:8,
                      Frequency = c(2,8,15,30,22,16,6,1))
ggplot(q3_data,aes(x = factor(Number_of_Letters),y = Frequency)) +
  geom_col(fill = "steelblue") +
  labs(title = "Number of Letters in 100 Words",
       x = "Number of Letters",
       y = "Frequency") +
  theme_gray()