#1
euclid_dist <- function(x1, y1, x2, y2) {
sqrt((x2 - x1)^2 + (y2 - y1)^2)}
#2a
calc_v <- function(u, a, t) {
v <- u + a*t
v}
#2b
calc_v2 <- function(u, a, d){
v <- sqrt(u^2 + 2*a*d)
v}
#2c
calc_d <- function(u, a, t){
d <- u*t + 0.5*a*t^2
d}
#3a • badd_two_nums(99, 100);badd_two_nums();badd_two_nums(y = -2); badd_two_nums(12) the result of all these codes is 5. The reason is that these codes did not contain any complecated math function in RStudio, such as seq, rep, and so on. Therefore, when we type in the simple function, badd_two_nums, it still get result according to the original function that we set as start. The original function is that function(x, y) {x <- 2, y <- 3, x + y}
# 3b
badd_two_nums <- function(x, y) {
x <- 2
y <- 3
x + y
}
# the problem of badd_two_nums() is that we must type two elements in this function for running successfully. The following codes might be its intended purpose.
badd_two_nums <- function(x, y) {
x + y
}
badd_two_nums(2,3)
## [1] 5