user7148318 user7148318 - 15 days ago 5
R Question

+- before a square root in R

I'm trying to write an equation in R (see code below). I was wondering how I can correctly use +- before sqrt() in my code?

x <- seq(0,1,by=0.01)
y <- %+-%sqrt((.5^2)-(x-.5)^2)+.5

Answer
x <- seq(0,1,by=0.01)
y1 <- sqrt((.5^2)-(x-.5)^2)+.5
y2 <- -sqrt((.5^2)-(x-.5)^2)+.5


plot(c(x,x), c(y1,y2))