Question 1

A signal’s total energy is represented by the definite integral below. Solve and graph this.

\[\int_{0}^{\frac{\pi}{2}} \sin(3x) \cos(3x) 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
f <- function(x) {
  sin(3 * x) * cos(3 * x)
}
total_energy <- integrate(f,lower = 0,upper = pi / 2)$value
x_values <- seq(0,3 * pi / 5,length.out = 500)
y_values <- f(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 >= 0 & x <= pi / 2),
              aes(ymin = 0,ymax = y),
              fill = "blue") +
  labs(title = "Graph of f(x) = sin(3x) cos(3x)",
       caption = paste("Total Energy:",round(total_energy,4)),
       x = "x",
       y = "y") +
  theme_gray(base_size = 14)

Question 2

Put \([2347,2374,3724,3247,4732,7432]\) in descending order.

# install.packages("tidyverse")
library(tidyverse)
q2_data <- data.frame(Numbers = c(2347,2374,3724,3247,4732,7432))
q2_data %>%
  arrange(desc(Numbers)) # arrange(): ascending order, desc(): descending order
##   Numbers
## 1    7432
## 2    4732
## 3    3724
## 4    3247
## 5    2374
## 6    2347

Question 3

Construct the polygon with the following points in the data frame below.

# install.packages("tidyverse")
library(tidyverse)
q3_data <- data.frame(X = c(0,-3,-6,-6,-3,-3,-6,-6,2,2,-1,-1,2,2),
                      Y = c(1,1,1,4,4,7,7,10,10,7,7,4,4,1))
ggplot(q3_data,aes(x = X,y = Y)) +
  geom_polygon(fill = "lightblue",alpha = 0.5,color = "black",lwd = 1.25) +
  geom_point(size = 3) +
  coord_equal() +
  theme_gray()

Question 4

Find the cube root of -836 correct to two decimal places.

# install.packages("pracma")
library(pracma)
## 
## Attaching package: 'pracma'
## The following object is masked from 'package:purrr':
## 
##     cross
value <- nthroot(x = -836,n = 3)
cat("The cube root of -836 is:",round(value,2),"\n")
## The cube root of -836 is: -9.42

Question 5

What is \(\int x(3x^2 - 2) dx\)?

# install.packages(c("ggformula","mosaicCalc"))
library(ggformula)
## Warning: package 'ggformula' was built under R version 4.5.2
## Loading required package: scales
## 
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor
## Loading required package: ggiraph
## Warning: package 'ggiraph' was built under R version 4.5.2
## Loading required package: ggridges
## Warning: package 'ggridges' was built under R version 4.5.2
## 
## New to ggformula?  Try the tutorials: 
##  learnr::run_tutorial("introduction", package = "ggformula")
##  learnr::run_tutorial("refining", package = "ggformula")
library(mosaicCalc)
## Warning: package 'mosaicCalc' was built under R version 4.5.2
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
## 
##     D
g <- makeFun(x * (3 * x^2 - 2) ~ x)
anti_g <- antiD(g(x) ~ x)
anti_g
## function (x, C = 0) 
## (3 * x^4 - 4 * x^2)/4 + C