中的R与绘制绝对值
答
这是一个数学问题而不是编程。一点计算会帮助编程任务变得更容易。
首先,为了简单起见,假定c_1
和c_2
等于零。我们可以通过移动轴来轻松恢复原始比例。然后,矩阵计算可以写成如下。
现在让z = ax + by
和w = cx + dy
。然后,绝对值指标的第一个方程就可以写成:
从这个等式,假设伽马是肯定的,你可以想像z
和w
如下。
所以,你可以找到一组满足要求,并转换回(x, y)
(z, w
)的组合。
具有最大度量的第二个方程可以写为如下:
这意味着(z, w)
可以如下可视化。
同样,你可以产生这样的(z, w)
对和转换回(x, y)
。
这是第一个等式的R代码。你可以自己尝试第二个。
library(ggplot2)
# A is (a,b; c,d) matrix
A <- matrix(c(1, 2, -1, 0),
nrow=2, ncol=2, byrow=TRUE)
gamma <- 1
c1 <- 0.2
c2 <- 0.1
###############################
z <- seq(-gamma, gamma, length=100)
w <- abs(gamma - abs(z))
z <- c(z, z)
w <- c(w, -w)
qplot(z, w) + coord_fixed()
# computing back (x,y) from (z,w)
z_mat <- rbind(z, w)
x_mat <- solve(A, z_mat)
x <- x_mat[1,] + c1
y <- x_mat[2,] + c2
qplot(x, y) + coord_fixed()
################################
你想要做什么?你想找到解决方程式的'(x,y)',还是想在图形中可视化? –
我需要可视化图形。 – Nile