How many composite numbers are there between 80 and 89 inclusive?
# install.packages(c("comprehenr","pracma"))
library(comprehenr)
## Warning: package 'comprehenr' was built under R version 4.5.2
library(pracma)
composite_numbers <- to_vec(for (x in 80:89) if (!isprime(x)) x)
cat("There are",length(composite_numbers),"composite numbers between 80 and 89 inclusive.")
## There are 8 composite numbers between 80 and 89 inclusive.
Evaluate and graph the following definite integral.
\[\int_{0}^{\frac{\pi}{2}} x \sin(x) \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() ──
## ✖ purrr::cross() masks pracma::cross()
## ✖ 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) {
x * sin(x)
}
answer <- integrate(f = f,lower = 0,upper = pi / 2)$value
x_values <- seq(0,pi / 2 + 0.01,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.5) +
geom_ribbon(data = subset(q1_data,x >= 0 & x <= pi / 2),
aes(ymin = 0,ymax = y),
fill = "purple") +
labs(title = "Graph of f(x) = x sin(x)",
caption = paste("Answer:",round(answer,4)),
x = "x",
y = "y") +
theme_gray()
Solve the following system of equations.
\[5x - 4y - z = 9 \\ -2x + y - 3z = -20 \\ 2x - 2y - 6z = -24\]
q3_data <- data.frame(X = c(5,-2,2),
Y = c(-4,1,-2),
Z = c(-1,-3,-6),
Constants = c(9,-20,-24))
q3_model <- lm(Constants ~ . - 1,data = q3_data)
coef(q3_model)
## X Y Z
## 2 -1 5