Compute \(\int (3x^2- 4x) (x^3 - 2x^2 + 7)^5 \space dx\) from a composite response function.
# install.packages(c("ggformula","mosaicCalc"))
library(ggformula)
## Warning: package 'ggformula' was built under R version 4.5.2
## Loading required package: ggplot2
## Loading required package: scales
## 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
f <- makeFun((3 * x^2 - 4 * x) * (x^3 - 2 * x^2 + 7)^5 ~ x)
anti_f <- antiD(f(x) ~ x)
anti_f
## function (x, C = 0)
## (x^18 - 12 * x^17 + 60 * x^16 - 118 * x^15 - 180 * x^14 + 1488 *
## x^13 - 2561 * x^12 - 2520 * x^11 + 16296 * x^10 - 16660 *
## x^9 - 29400 * x^8 + 82320 * x^7 - 18865 * x^6 - 144060 *
## x^5 + 144060 * x^4 + 100842 * x^3 - 201684 * x^2)/6 + C
Carl spins the spinner twice and adds the two scores together. He wins if he gets a total score of 9. What is the probability of winning?
spinner <- c(3,1,5,1,5,2,1,5)
N <- 1e5
counter <- 0
for (i in 1:N) {
spin1 <- sample(x = spinner,size = 1,replace = T)
spin2 <- sample(x = spinner,size = 1,replace = T)
if (spin1 + spin2 >= 9) {
counter <- counter + 1
}
}
probability <- counter / N
cat("The probability of winning is:",probability,"\n")
## The probability of winning is: 0.14159
Solve and graph the following definite integral.
\[\int_{-6}^{-2} -x^2 - 5x + 6 \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 ──
## ✔ forcats 1.0.1 ✔ stringr 1.5.2
## ✔ lubridate 1.9.4 ✔ tibble 3.3.0
## ✔ purrr 1.1.0 ✔ tidyr 1.3.1
## ✔ readr 2.1.5
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ readr::col_factor() masks scales::col_factor()
## ✖ purrr::discard() masks scales::discard()
## ✖ tidyr::expand() masks Matrix::expand()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ tidyr::pack() masks Matrix::pack()
## ✖ tidyr::unpack() masks Matrix::unpack()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
g <- function(x) {
-x^2 - 5 * x + 6
}
answer <- integrate(f = g,lower = -6,upper = -2)$value
x_values <- seq(-6.01,-1.99,length.out = 500)
y_values <- g(x_values)
q3_data <- data.frame(x = x_values,y = y_values)
ggplot(q3_data,aes(x = x,y = y)) +
geom_line(col = "black",lwd = 2) +
geom_ribbon(data = subset(q3_data,x >= -6 & x <= -2),
aes(ymin = 0,ymax = y),
fill = "steelblue") +
labs(title = "Graph of g(x) = -x^2 - 5x + 6",
caption = paste("Answer:",round(answer,4)),
x = "x",
y = "y") +
theme_gray()