gpt4 book ai didi

julia - Julia 中的 3D 曲面图

转载 作者:行者123 更新时间:2023-12-02 18:54:08 24 4
gpt4 key购买 nike

我想知道如何将以下代码中的数据绘制为 3D-surface

using Plots
function f(x)
x1=x[1]
x2=x[2]
sin(x[1]) + cos(x[2])
end
#Sampling
function sam()
x = range(0, 10.0, length = 9) |> collect
y = range(0, 10.0, length = 9) |> collect
tuple = zip(x,y) |> collect
return tuple
end
xy = sam()
z = f.(xy)
plot(getindex.(xy,1),getindex.(xy,2),z)

我尝试在 plots() 函数中使用 st=:surfacegr()pyplot() 作为后端,但它不起作用。我可以知道如何将其绘制为 x,y,z 范围内的表面吗?

最佳答案

看起来你想做

julia> using Plots

julia> f(x, y) = sin(x) + cos(y)
f (generic function with 1 method)

julia> surface(0:0.1:10, 0:0.1:10, f)

给出

enter image description here

如果你想显式构建网格,你可以这样做

julia> x = y = 0:0.1:10
0.0:0.1:10.0

julia> z = f.(x', y) ; # note the ' which permutes the dims of x

julia> surface(x, y, z)

关于julia - Julia 中的 3D 曲面图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66417677/

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