2017-09-15 144 views
1

我不知道是否有繪製以下兩個方程中的R中的R與繪製絕對值

x和y一個簡單的方法是變量,其餘爲已知的參數。

enter image description here

enter image description here

當X爲維度的向量n然後

enter image description here

enter image description here

+0

你想要做什麼?你想找到解決方程式的'(x,y)',還是想在圖形中可視化? –

+0

我需要可視化圖形。 – Nile

回答

1

這是一個數學問題而不是編程。一點計算會幫助編程任務變得更容易。

首先,爲了簡單起見,假定c_1c_2等於零。我們可以通過移動軸來輕鬆恢復原始比例。然後,矩陣計算可以寫成如下。

enter image description here

現在讓z = ax + byw = cx + dy。然後,絕對值指標的第一個方程就可以寫成:

enter image description here

從這個等式,假設伽馬是肯定的,你可以想像zw如下。

enter image description here

所以,你可以找到一組滿足要求,並轉換回(x, y)z, w)的組合。

具有最大度量的第二個方程可以寫爲如下:

enter image description here

這意味着(z, w)可以如下可視化。

enter image description here

同樣,你可以產生這樣的(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() 
################################