Evaluate the following limit.
\[\lim_{x \to 0} \frac{4x - 8x^2}{x}\]
# install.packages("Ryacas")
library(Ryacas)
## Warning: package 'Ryacas' was built under R version 4.5.2
##
## Attaching package: 'Ryacas'
## The following object is masked from 'package:stats':
##
## integrate
## The following objects are masked from 'package:base':
##
## %*%, det, diag, diag<-, lower.tri, upper.tri
x <- ysym("x")
g <- (4 * x - 8 * x^2) / (x)
result <- lim(g,x,0)
result
## y: 4
What is the area between the curve \(f(x) = x^3 - 4x^2 + x + 6\) and the \(x\)-axis from \(x = -1\) to \(x = 3\)?
# 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()
## ✖ purrr::simplify() masks Ryacas::simplify()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
f <- function(x) {
x^3 - 4 * x^2 + x + 6
}
answer <- integrate(f,lower = -1,upper = 3)$value
x_values <- seq(-2,4,length.out = 500)
y_values <- f(x_values)
q2_data <- data.frame(x = x_values,y = y_values)
ggplot(q2_data,aes(x = x,y = y)) +
geom_line(col = "black",lwd = 1.25) +
geom_ribbon(data = subset(q2_data,x >= -1 & x <= 3),
aes(ymin = 0,ymax = y),
fill = "blue") +
labs(title = "Graph of f(x) = x^3 - 4x^2 + x + 6",
caption = paste("The area under the curve from x = -1 to x = 3 is:",round(answer,4)),
x = "x",
y = "y") +
theme_gray(base_size = 14)
Ben takes an ordinary deck of 52 playing cards and removes all the picture cards - all the Jacks, Queens, and Kings. He then shuffles the remaining cards and selects a card at random. Answer the following questions below.
A. What is the probability Ben selects a card that is a prime number?
Note: We will assume that the Ace is a 1.
# install.packages("pracma")
library(pracma) # for the isprime() function
##
## Attaching package: 'pracma'
## The following object is masked from 'package:purrr':
##
## cross
cards <- 1:10 # cards 1 (Ace) to 10 inclusive
counter <- 0 # number of prime numbers
N <- 10000 # number of trials
for (x in 1:N) {
card <- sample(x = cards,size = 1,replace = T)
if (isprime(card) == TRUE) {
counter <- counter + 1
}
}
probability <- counter / N
cat("The probability of Ben selecting a card that is a prime number is:",probability,"\n")
## The probability of Ben selecting a card that is a prime number is: 0.401
B. What about selecting a card that is not a prime number?
# install.packages("pracma")
library(pracma) # for the isprime() function
cards <- 1:10 # cards 1 (Ace) to 10 inclusive
counter2 <- 0 # number of cards that are not prime
N <- 10000 # number of trials
for (y in 1:N) {
card2 <- sample(x = cards,size = 1,replace = T)
if (isprime(card2) == FALSE) {
counter2 <- counter2 + 1
}
}
probability2 <- counter2 / N
cat("The probability of Ben selecting a card that is not a prime number is:",probability2,"\n")
## The probability of Ben selecting a card that is not a prime number is: 0.5948