+- 在 R 中的平方根之前
+- before a square root in R
我正在尝试用 R 写一个方程(见下面的代码)。我想知道如何在代码中的 sqrt() 之前正确使用 +-?
x <- seq(0,1,by=0.01)
y <- %+-%sqrt((.5^2)-(x-.5)^2)+.5
需要单独绘制它们,但可以在 plotmath 表达式中使用 %+-%
运算符。但是,需要在两个值的两侧,因此需要使用非打印 phantom():
x <- c( seq(0,1,by=0.01) )
y <- c( sqrt((.5^2)-(x-.5)^2)+.5, -sqrt((.5^2)-(x-.5)^2)+.5)
plot( rep(x,times=2), y)
title(main= bquote( phantom(0) %+-% sqrt((.5^2)-(x-.5)^2)+.5))
您可能希望使用参数形式的方程,而不需要 sqrt 的 +-。
theta <- seq(0,2*pi,0.01)
x <- 0.5 + 0.5*sin(theta)
y <- 0.5 + 0.5*cos(theta)
plot(x, y)
title(main= substitute(paste('x=(1+sin',theta,')/2, y=(1+cos', theta, ')/2')))
试试这个:
draw.circle <- function(stepsize=.01) {
theta <- seq(0,2*pi,by=stepsize)
x <- 0.5 + 0.5*sin(theta)
y <- 0.5 + 0.5*cos(theta)
plot(x, y,type="n",xlim = c(0,1),ylim = c(0,1))
segments(x,y,.5,.5)
}
draw.circle(.01)
draw.circle(.02)
draw.circle(.05)
我正在尝试用 R 写一个方程(见下面的代码)。我想知道如何在代码中的 sqrt() 之前正确使用 +-?
x <- seq(0,1,by=0.01)
y <- %+-%sqrt((.5^2)-(x-.5)^2)+.5
需要单独绘制它们,但可以在 plotmath 表达式中使用 %+-%
运算符。但是,需要在两个值的两侧,因此需要使用非打印 phantom():
x <- c( seq(0,1,by=0.01) )
y <- c( sqrt((.5^2)-(x-.5)^2)+.5, -sqrt((.5^2)-(x-.5)^2)+.5)
plot( rep(x,times=2), y)
title(main= bquote( phantom(0) %+-% sqrt((.5^2)-(x-.5)^2)+.5))
您可能希望使用参数形式的方程,而不需要 sqrt 的 +-。
theta <- seq(0,2*pi,0.01)
x <- 0.5 + 0.5*sin(theta)
y <- 0.5 + 0.5*cos(theta)
plot(x, y)
title(main= substitute(paste('x=(1+sin',theta,')/2, y=(1+cos', theta, ')/2')))
试试这个:
draw.circle <- function(stepsize=.01) {
theta <- seq(0,2*pi,by=stepsize)
x <- 0.5 + 0.5*sin(theta)
y <- 0.5 + 0.5*cos(theta)
plot(x, y,type="n",xlim = c(0,1),ylim = c(0,1))
segments(x,y,.5,.5)
}
draw.circle(.01)
draw.circle(.02)
draw.circle(.05)