Question 1

Find the first derivative of the function \(f(x) = \frac{x^2 + 3}{\cos(x)}\).

# install.packages("Deriv")
library(Deriv)
f <- function(x) {
  (x^2 + 3) / (cos(x))
}
f_prime <- Deriv(f)
f_prime
## function (x) 
## {
##     .e1 <- cos(x)
##     ((3 + x^2) * sin(x)/.e1 + 2 * x)/.e1
## }

Question 2

Find the value of \(C\) if \(C = A \times B\) where \(A = \begin{bmatrix} 16 & -1 & 6 & -20 \end{bmatrix}\) and \(B = \begin{bmatrix} 10 \\ 19 \\ -19 \\ 1 \end{bmatrix}\).

A <- matrix(data = c(16,-1,6,-20),nrow = 1,ncol = 4,byrow = T)
B <- matrix(data = c(10,19,-19,1),nrow = 4,ncol = 1,byrow = T)
if (nrow(B) == ncol(A)) {
  C <- A %*% B
  C
} else {
  cat("The value of C does not exist due to insufficient matrix dimensions.","\n")
}
##      [,1]
## [1,]    7

Question 3

Which animal is the lightest one of the animals?

Note: All weights are in pounds (lbs.).

  1. Define the data frame.
q3_data <- data.frame(Animal = c("Cat","Bird","Eagle","Lion","Centipeed","St. Bernard","Chihuahua","Elephant","Catfish","Polar Bear","Hummingbird","Dog"),
                      Weight = c(9,4,13,420,0.00625,180,5,12000,30,1100,0.0125,25))
q3_data
##         Animal   Weight
## 1          Cat 9.00e+00
## 2         Bird 4.00e+00
## 3        Eagle 1.30e+01
## 4         Lion 4.20e+02
## 5    Centipeed 6.25e-03
## 6  St. Bernard 1.80e+02
## 7    Chihuahua 5.00e+00
## 8     Elephant 1.20e+04
## 9      Catfish 3.00e+01
## 10  Polar Bear 1.10e+03
## 11 Hummingbird 1.25e-02
## 12         Dog 2.50e+01
  1. Determine the animal with the lightest weight.
# 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
lightest_weight <- q3_data %>%
  filter(Weight == min(Weight)) %>%
  pull(Animal)
cat("The animal with the lightest weight is:",lightest_weight,"\n")
## The animal with the lightest weight is: Centipeed

Question 4

How many even numbers are there between 1 and 900 inclusive?

# install.packages("comprehenr")
library(comprehenr)
## Warning: package 'comprehenr' was built under R version 4.5.2
even_numbers <- to_vec(for (x in 1:900) if (x %% 2 == 0) x)
cat("There are",length(even_numbers),"even numbers between 1 and 900 inclusive.","\n")
## There are 450 even numbers between 1 and 900 inclusive.