沿朱莉娅速度场移动的情节点

发布于 2025-01-28 10:37:32 字数 598 浏览 2 评论 0 原文

下面的代码创建速度字段。我在(0.5,0.5)中绘制了一个蓝点。如何绘制一系列与速度场一起移动的点?

using PyPlot

xs = range(0,1,step=0.03)
ys = range(0,1,step=0.03)

nfreq = 20
as = randn(nfreq, nfreq)
aas = randn(nfreq, nfreq)
bs = randn(nfreq, nfreq)
bbs = randn(nfreq, nfreq)

f(x,y) = sum( as[i,j]*sinpi(x*i+ aas[i,j])*sinpi(y*j )/(i^2+j^2)^(1.5) for i=1:nfreq, j=1:nfreq)
g(x,y) = sum( bs[i,j]*sinpi(x*i)*sinpi(y*j + bbs[i,j])/(i^2+j^2)^(1.5) for i=1:nfreq, j=1:nfreq)

quiver(xs,ys, f.(xs,ys'), g.(xs,ys'))

The code below creates velocity field. I plotted a blue point in (0.5,0.5). How do I plot series of points that move alongside the velocity field?

using PyPlot

xs = range(0,1,step=0.03)
ys = range(0,1,step=0.03)

nfreq = 20
as = randn(nfreq, nfreq)
aas = randn(nfreq, nfreq)
bs = randn(nfreq, nfreq)
bbs = randn(nfreq, nfreq)

f(x,y) = sum( as[i,j]*sinpi(x*i+ aas[i,j])*sinpi(y*j )/(i^2+j^2)^(1.5) for i=1:nfreq, j=1:nfreq)
g(x,y) = sum( bs[i,j]*sinpi(x*i)*sinpi(y*j + bbs[i,j])/(i^2+j^2)^(1.5) for i=1:nfreq, j=1:nfreq)

quiver(xs,ys, f.(xs,ys'), g.(xs,ys'))

plot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪漫人生路 2025-02-04 10:37:32

您可以使用 dindicalialequations.jl ,特别是来自 pronishare -diffeq.jl

<

在这种情况下,要计算从 [0.1,0.1] 开始的轨迹,我们可以做类似的事情:

using OrdinaryDiffEq

F(x, y) = [f(x, y), g(x, y)]
F(u) = F(u...)
# For ODE solver
F(u, t, p) = F(u)

u0 = [0.1, 0.1]
tspan = (0.0, 1.0)
prob = OrdinaryDiffEq.ODEProblem(F, u0, tspan)
sol = OrdinaryDiffEq.solve(prob, OrdinaryDiffEq.Tsit5())

这使用标准求解器之一来计算轨迹。
f(u,t,p)方法定义为符合 odeproblem 预期的签名。

输出 sol 是一种特殊的数据结构,可存储(自动选择)时间点,轨迹/解决方案数据以及有关计算方式的一些信息:

julia> sol

retcode: Success
Interpolation: specialized 4th order "free" interpolation
t: 16-element Vector{Float64}:
 0.0
 0.016059769627848473
 0.05687861311174197
 0.11905519520284545
 0.1762669960378554
 0.24797417284787635
 0.3389099429346001
 0.4168117846405069
 0.5058131414831007
 0.5832877232134522
 0.6673494607419321
 0.7443426334531882
 0.8182342011387053
 0.89201972618978
 0.9834140190395773
 1.0
u: 16-element Vector{Vector{Float64}}:
 [0.1, 0.1]
 [0.10110680137385687, 0.10198760564184167]
 [0.10406194191642619, 0.10713626068506982]
 [0.10896217507542232, 0.11524940132731033]
 [0.11390233972543964, 0.12300643621930929]
 [0.1206820706605841, 0.13312809220811475]
 [0.13023297520058397, 0.14662230992549455]
 [0.1392904751559556, 0.15881027331987904]
 [0.15068267631556032, 0.17352625961041768]
 [0.16157943680595235, 0.18709637923697067]
 [0.17457595399222012, 0.20265945610197006]
 [0.1877136474604169, 0.21764486386096143]
 [0.2015199067922626, 0.23261870623234943]
 [0.21645294590353964, 0.2481557501686445]
 [0.236427795874632, 0.26846545434236724]
 [0.24021585799812886, 0.27231898207853394]

要访问轨迹本身,请使用 sol.u

julia> sol.u
16-element Vector{Vector{Float64}}:
 [0.1, 0.1]
 [0.10110680137385687, 0.10198760564184167]
 [0.10406194191642619, 0.10713626068506982]
 [0.10896217507542232, 0.11524940132731033]
 [0.11390233972543964, 0.12300643621930929]
 [0.1206820706605841, 0.13312809220811475]
 [0.13023297520058397, 0.14662230992549455]
 [0.1392904751559556, 0.15881027331987904]
 [0.15068267631556032, 0.17352625961041768]
 [0.16157943680595235, 0.18709637923697067]
 [0.17457595399222012, 0.20265945610197006]
 [0.1877136474604169, 0.21764486386096143]
 [0.2015199067922626, 0.23261870623234943]
 [0.21645294590353964, 0.2481557501686445]
 [0.236427795874632, 0.26846545434236724]
 [0.24021585799812886, 0.27231898207853394]

然后,您可以将此数据绘制为散点图以及向量字段本身。

You could use DifferentialEquations.jl, specifically one of the ODE solvers from OrdinaryDiffEq.jl.

Here is a basic (but very useful) tutorial.

In this case, to compute the trajectory starting at [0.1, 0.1], we could do something like:

using OrdinaryDiffEq

F(x, y) = [f(x, y), g(x, y)]
F(u) = F(u...)
# For ODE solver
F(u, t, p) = F(u)

u0 = [0.1, 0.1]
tspan = (0.0, 1.0)
prob = OrdinaryDiffEq.ODEProblem(F, u0, tspan)
sol = OrdinaryDiffEq.solve(prob, OrdinaryDiffEq.Tsit5())

This uses one of the standard solvers to compute the trajectory.
The F(u,t,p) method is defined to comply with the signature expected by ODEProblem.

The output sol is a special data structure that stores the (automatically-chosen) time points, the trajectory/solution data, and some info about how the computation went:

julia> sol

retcode: Success
Interpolation: specialized 4th order "free" interpolation
t: 16-element Vector{Float64}:
 0.0
 0.016059769627848473
 0.05687861311174197
 0.11905519520284545
 0.1762669960378554
 0.24797417284787635
 0.3389099429346001
 0.4168117846405069
 0.5058131414831007
 0.5832877232134522
 0.6673494607419321
 0.7443426334531882
 0.8182342011387053
 0.89201972618978
 0.9834140190395773
 1.0
u: 16-element Vector{Vector{Float64}}:
 [0.1, 0.1]
 [0.10110680137385687, 0.10198760564184167]
 [0.10406194191642619, 0.10713626068506982]
 [0.10896217507542232, 0.11524940132731033]
 [0.11390233972543964, 0.12300643621930929]
 [0.1206820706605841, 0.13312809220811475]
 [0.13023297520058397, 0.14662230992549455]
 [0.1392904751559556, 0.15881027331987904]
 [0.15068267631556032, 0.17352625961041768]
 [0.16157943680595235, 0.18709637923697067]
 [0.17457595399222012, 0.20265945610197006]
 [0.1877136474604169, 0.21764486386096143]
 [0.2015199067922626, 0.23261870623234943]
 [0.21645294590353964, 0.2481557501686445]
 [0.236427795874632, 0.26846545434236724]
 [0.24021585799812886, 0.27231898207853394]

To access the trajectory itself, use sol.u:

julia> sol.u
16-element Vector{Vector{Float64}}:
 [0.1, 0.1]
 [0.10110680137385687, 0.10198760564184167]
 [0.10406194191642619, 0.10713626068506982]
 [0.10896217507542232, 0.11524940132731033]
 [0.11390233972543964, 0.12300643621930929]
 [0.1206820706605841, 0.13312809220811475]
 [0.13023297520058397, 0.14662230992549455]
 [0.1392904751559556, 0.15881027331987904]
 [0.15068267631556032, 0.17352625961041768]
 [0.16157943680595235, 0.18709637923697067]
 [0.17457595399222012, 0.20265945610197006]
 [0.1877136474604169, 0.21764486386096143]
 [0.2015199067922626, 0.23261870623234943]
 [0.21645294590353964, 0.2481557501686445]
 [0.236427795874632, 0.26846545434236724]
 [0.24021585799812886, 0.27231898207853394]

You could then plot this data as a scatter plot along with the vector field itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文