使用给定两个向量的条件在 R 图上绘制曲线

Plot curved line on R plot using a condition given two vectors

给定以下空图:

plot(1, type="n", xlab="x1", ylab="x2", xlim=c(0, 10), ylim=c(0, 10), axes = F)
axis(1, seq(0,10,1), pos = 0)
axis(2, seq(0,10,1), pos = 0)
lines(x = c(0,10), y = c(10,10))
lines(x = c(10,10), y = c(0,10))

我想绘制一条平滑的曲线,其中 x1*x2 = 38,假设 x1 和 x2 都在 0 和 10 之间。

我可以使用什么样的函数来完成这个?

你可以试试

plot(1, type="n", xlab="x1", ylab="x2", xlim=c(0, 10), ylim=c(0, 10), axes = F)
axis(1, seq(0,10,1), pos = 0)
axis(2, seq(0,10,1), pos = 0)
lines(x = c(0,10), y = c(10,10))
lines(x = c(10,10), y = c(0,10))
t <- seq(from = 3.8, to = 10, by = .1)
lines(x = t, y = 38/t)

使用 curve.

curve(38/x, xlim=c(0, 10), ylim=c(0, 10), xlab='x1', ylab='x2')