pg.73-74: 21. Write a program to simulate the problem described in Exercise 16:
A = c(0,0)
B = c(runif(n=1,min=-1,max=1),runif(n=1,min=-1,max=1))
C = c(runif(n=1,min=-1,max=1),runif(n=1,min=-1,max=1))
Since the first point (point A) is (0,0), in order for all angles to be acute, points B and C should both be in the same quadrant, meaning that both their x and y values should have matching signs (both positive or both negative).
library(data.table)
# create empty dataframe
matching = data.frame(matches = 0)
matching
## matches
## 1 0
n = 101
# create a loop where that prints out if coordinates have same sign
for (i in 1:n){
for (i in length(matching)){
if((B[1]&C[1]<0 | B[1]&C[1]>0) & (B[2]&C[2]<0 | B[2]&C[2]>0)){
new = data.frame(matches = 1)
matching = rbind(matching, new)
} else {
new = data.frame(matches = 0)
matching = rbind(matching, new)
}
}
}
# how many out of the runs printed matching (aka 1)
prob = (length(matching$matches== 1)/n-1)*100
prob
## [1] 0.990099