gpt4 book ai didi

r - 在 plotly 中从 x+y+z=6 方程绘制 3d 平面

转载 作者:行者123 更新时间:2023-12-05 05:49:09 26 4
gpt4 key购买 nike

我有一组方程式 (z1) x+y+z=6、(z2) x+2y+2z=9 和 (z3) x+3y+4z=13,我想使用 plotly 绘制平面.

方法一:使用mesh3d

require(plotly)

x<-seq(from=-10, to=10, by=1)
y<-seq(from=-10, to=10, by=1)
z1<-6-x-y #For the first plane

fig <- plot_ly(x = ~, y = ~y, z = ~z1, type = 'mesh3d')
fig

虽然不产生任何输出。为什么?

方法二:利用表面

虽然这会产生一个平面但错误的平面。

library(plotly)

x<-seq(from=-10,to=10,by=1)
y<-seq(from=-10,to=10,by=1)

z1<-6-x-y
z1<-matrix(rep(z1,10),NROW(x),10)

fig <- plot_ly(showscale = FALSE)
fig <- fig %>% add_surface(z = ~z1)
fig

这个平面不正确。如果您查看点 x=2、y=2,z 应该等于 2,但事实并非如此。相反,它是 22,这是不正确的。

enter image description here

最佳答案

x <- seq(from=-10, to=10, by=1); y<-seq(from=-10, to=10, by=1) , x+y+z=6 不是平面而是直线。
您需要准备更多的数据点。

library(dplyr); library(tidyr); library(plotly)

x <- seq(from=-10, to=10, by=1)
y <- seq(from=-10, to=10, by=1)
z1 <- 6-x-y #For the first plane

origin <- tibble(x = x, y = y, z = z1)
# prepare all combination of x and y, and calculate z1
xyz1 <- tidyr::crossing(x, y) %>%
mutate(z1 = 6-x-y)

plot_ly(x = ~x, y = ~y, z = ~z1, type = "mesh3d", data = xyz1) %>%
add_markers(~ x, ~y, ~z1, data = origin)

橙色点是您准备的数据(当 x <- seq(from=-10, to=10, by=1); y<-seq(from=-10, to=10, by=1) 时,x+y+z=6 是直线。) enter image description here

关于r - 在 plotly 中从 x+y+z=6 方程绘制 3d 平面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70699740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com