Evaluate and graph the following definite integral.
\[\int_{4}^{5} x^3 + 2x + 5 \space dx\]
# 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
g <- function(x) {
x^3 + 2 * x + 5
}
value <- integrate(g,lower = 4,upper = 5)$value
x_values <- seq(3,6,length.out = 500)
y_values <- g(x_values)
q1_data <- data.frame(x = x_values,y = y_values)
ggplot(q1_data,aes(x = x,y = y)) +
geom_line(col = "black",lwd = 1.25) +
geom_ribbon(data = subset(q1_data,x >= 4 & x <= 5),
aes(ymin = 0,ymax = y),
fill = "blue") +
labs(title = "Graph of f(x) = x^3 + 2x + 5",
caption = paste("Answer:",value),
x = "x",
y = "y") +
theme_gray(base_size = 14)
Find the first and second derivatives of the function \(f(x) = \sec(x)\).
# install.packages("Deriv")
library(Deriv)
f <- function(x) {
1 / cos(x) # sec(x) = 1 / cos(x) - define it this way due to the Deriv package capability
}
f_prime <- Deriv(f) # f'(x)
f_double_prime <- Deriv(f_prime) # f''(x)
cat("f'(x) =","\n")
## f'(x) =
print(f_prime)
## function (x)
## sin(x)/cos(x)^2
cat("f''(x) =","\n")
## f''(x) =
print(f_double_prime)
## function (x)
## {
## .e1 <- cos(x)
## (1 + 2 * (sin(x)^2/.e1^2))/.e1
## }
Calculate descriptive statistics for \([15,12,10,13]\).
# install.packages("summarytools")
library(summarytools)
##
## Attaching package: 'summarytools'
## The following object is masked from 'package:tibble':
##
## view
nums <- c(15,12,10,13)
descr(nums)
## Descriptive Statistics
## nums
## N: 4
##
## nums
## ----------------- --------
## Mean 12.50
## Std.Dev 2.08
## Min 10.00
## Q1 11.00
## Median 12.50
## Q3 14.00
## Max 15.00
## MAD 2.22
## IQR 2.00
## CV 0.17
## Skewness 0.00
## SE.Skewness 1.01
## Kurtosis -1.96
## N.Valid 4.00
## N 4.00
## Pct.Valid 100.00
Four friends - Dan, Fran, Ian, Jan - went strawberry picking last Saturday. The data below shows the number of punnets of strawberries each of them picked. How many more punnets of strawberries did Dan pick than Jan picked?
q4_data <- data.frame(Friend = c("Dan","Fran","Ian","Jan"),
Number = c(35,20,30,25))
q4_data
## Friend Number
## 1 Dan 35
## 2 Fran 20
## 3 Ian 30
## 4 Jan 25
# install.packages("tidyverse")
library(tidyverse)
dan <- q4_data %>%
filter(Friend == "Dan") %>%
pull(Number)
jan <- q4_data %>%
filter(Friend == "Jan") %>%
pull(Number)
cat("Dan picked",dan - jan,"more strawberries than Jan.","\n")
## Dan picked 10 more strawberries than Jan.
Arrange these products and prices in order from greatest price to least price.
q5_data <- data.frame(Product = c("Salt","Bread","Tissues","Toothbrush"),
Price = c(0.55,0.99,0.79,0.95))
q5_data
## Product Price
## 1 Salt 0.55
## 2 Bread 0.99
## 3 Tissues 0.79
## 4 Toothbrush 0.95
# install.packages("tidyverse")
library(tidyverse)
q5_data %>%
arrange(desc(Price))
## Product Price
## 1 Bread 0.99
## 2 Toothbrush 0.95
## 3 Tissues 0.79
## 4 Salt 0.55
How many of the square numbers between 0 and 200 have one of their digits equal to 9?
# install.packages("comprehenr")
library(comprehenr)
## Warning: package 'comprehenr' was built under R version 4.5.2
valid_numbers <- to_vec(for (x in 0:200) if (sqrt(x) %% 1 == 0 & grepl("9",as.character(x))) x)
cat("There are",length(valid_numbers),"perfect square numbers that have one of their digits equal to 9.","\n")
## There are 4 perfect square numbers that have one of their digits equal to 9.