Find the value(s) of \(x\) where the function \(f(x) = 323x + 29x^2 - 300\) has a zero value.
# install.packages(c("tidyverse","rootSolve"))
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
library(rootSolve)
f <- function(x) {
323 * x + 29 * x^2 - 300
}
roots <- uniroot.all(f,c(-10,10))
for (x in seq_along(roots)) {
cat("Root",x,":",roots[x],"\n")
}
## Root 1 : 0.862069
x_values <- seq(0,2,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) +
annotate("point",x = roots[1],y = f(roots[1]),col = "blue",size = 5) +
labs(title = "Graph of f(x) = 323x + 29x^2 - 300",
caption = paste("Roots:",round(roots[1],2)),
x = "x",
y = "y") +
theme_gray(base_size = 14)
How many odd numbers are there in \([2,10,16,4,14,8,12,18,6,9,3,15,21]\)?
# install.packages("comprehenr")
library(comprehenr)
## Warning: package 'comprehenr' was built under R version 4.5.2
odd_nums <- to_vec(for (i in c(2,10,16,4,14,8,12,18,6,9,3,15,21)) if (i %% 2 == 1) i)
cat("There are",length(odd_nums),"odd numbers in [2,10,16,4,14,8,12,18,6,9,3,15,21].","\n")
## There are 4 odd numbers in [2,10,16,4,14,8,12,18,6,9,3,15,21].
Put \([5401,1058,1085,4510,4501,5104]\) in ascending order.
nums <- c(5401,1058,1085,4510,4501,5104)
sort(nums,decreasing = F) # ascending order
## [1] 1058 1085 4501 4510 5104 5401
# install.packages("tidyverse")
library(tidyverse)
q3_data <- data.frame(nums = c(5401,1058,1085,4510,4501,5104))
q3_data %>%
arrange(nums) # ascending order
## nums
## 1 1058
## 2 1085
## 3 4501
## 4 4510
## 5 5104
## 6 5401
Solve the system of linear equations below.
\[25x - 8y = 14 \\ 11x + 6y = 27\]
q4_data <- data.frame(x = c(25,11),
y = c(-8,6),
constants = c(14,27))
q4_model <- lm(constants ~ . - 1,data = q4_data)
coef(q4_model)
## x y
## 1.260504 2.189076
What is \(\int x^2 \cos(x) 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^2 * cos(x) ~ x)
anti_g <- antiD(g(x) ~ x)
anti_g
## function (x, C = 0)
## x^2 * sin(x) + 2 * cos(x) + C