Find the derivative of \(f(x) = x^3 + 4x^2 + x\).
# install.packages("Deriv")
library(Deriv)
f <- function(x) {
x^3 + 4 * x^2 + x
}
f_prime <- Deriv(f)
f_prime
## function (x)
## 1 + x * (3 * x + 8)
Evaluate: \(\frac{d}{dx} \lbrace 2 \sin(x) \cos(x) \rbrace\).
# install.packages("Deriv")
library(Deriv)
g <- function(x) {
2 * sin(x) * cos(x)
}
g_prime <- Deriv(g)
g_prime
## function (x)
## 2 * (cos(x)^2 - sin(x)^2)
Calculate descriptive statistics for \([1,2,5,7,7,9,15,15,15,22,23,24,26]\).
# install.packages("summarytools")
library(summarytools)
nums <- c(1,2,5,7,7,9,15,15,15,22,23,24,26)
descr(nums)
## Descriptive Statistics
## nums
## N: 13
##
## nums
## ----------------- --------
## Mean 13.15
## Std.Dev 8.66
## Min 1.00
## Q1 7.00
## Median 15.00
## Q3 22.00
## Max 26.00
## MAD 11.86
## IQR 15.00
## CV 0.66
## Skewness 0.09
## SE.Skewness 0.62
## Kurtosis -1.61
## N.Valid 13.00
## N 13.00
## Pct.Valid 100.00
Find the norm of the vector \(\vec{v} = (-1,3,2,2)\).
# install.packages("pracma")
library(pracma)
v <- c(-1,3,2,2)
norm_v <- Norm(v)
cat("The norm of vector v is:",norm_v,"\n")
## The norm of vector v is: 4.242641
You are given the data frame below with several objects and their weights. Determine which object has the highest weight.
Note: Weight is defined in pounds (lb.) except where there are asterisks (*). These weights are defined in tons. Keep in mind that 1 ton is 2000 pounds.
q5_data <- data.frame(Object = c("Kayak","Truck","Boat","Scooter","Plane*","Racecar","Motorcycle","Car","Cruise Ship*","Bike"),
Weight = c(40,16000,1600,27,400,1600,350,3300,100000,15))
q5_data
## Object Weight
## 1 Kayak 40
## 2 Truck 16000
## 3 Boat 1600
## 4 Scooter 27
## 5 Plane* 400
## 6 Racecar 1600
## 7 Motorcycle 350
## 8 Car 3300
## 9 Cruise Ship* 100000
## 10 Bike 15
# 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() ──
## ✖ purrr::cross() masks pracma::cross()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ tibble::view() masks summarytools::view()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
heaviest_object <- q5_data %>%
mutate(Weight = if_else(
str_detect(Object,"\\*"), # finding the asterisk "*"
Weight * 2000, # if an asterisk is present, multiply value by 2000 (1 ton = 2000 lbs.)
Weight # keeping value if no asterisk at all
)) %>%
slice_max(Weight,n = 1) %>% # getting the maximum weight
pull(Object) %>% # extracting the object with the maximum weight
str_remove("\\*") # removing asterisk from final result
cat("The object with the highest weight is:",heaviest_object,"\n")
## The object with the highest weight is: Cruise Ship