如何在Mathematica中获得准确的绘图曲线?

发布于 2024-11-29 17:15:10 字数 655 浏览 3 评论 0原文

在 Mathematica 中运行以下代码:

r=6197/3122;
p[k_,w_]:=Sqrt[w^2/r^2-k^2];q[k_,w_]:=Sqrt[w^2-k^2];
a[k_,w_,p_,q_]:=(k^2-q^2)^2 Sin[p]Cos[q]+4k^2 p q Cos[p]Sin[q]
a[k_,w_]:=a[k,w,p[k,w],q[k,w]];
ContourPlot[a[k,w]==0,{w,0,6},{k,0,14}]

这给了我非常不准确的曲线:

从上面的代码获得的曲线非常不准确

我有尝试将 ContourPlotPlotPointsWorkingPrecision 选项分别设置为 30 和 20,但无济于事。您还会注意到,唯一的数字参数 r 是一个精确的有理数。我不知道还能尝试什么。谢谢。

编辑:我期望得到的曲线是下图中的三个黑色曲线(标记为 A1、A2 和 A3)

Expected curve (黑色的)

Run the following code In Mathematica:

r=6197/3122;
p[k_,w_]:=Sqrt[w^2/r^2-k^2];q[k_,w_]:=Sqrt[w^2-k^2];
a[k_,w_,p_,q_]:=(k^2-q^2)^2 Sin[p]Cos[q]+4k^2 p q Cos[p]Sin[q]
a[k_,w_]:=a[k,w,p[k,w],q[k,w]];
ContourPlot[a[k,w]==0,{w,0,6},{k,0,14}]

This gives me very inaccurate curves:

The curves obtained from the code above are very inaccurate

I have tried setting the PlotPoints and WorkingPrecision options of ContourPlot to 30 and 20 respectively, to no avail. You will also notice that the only numerical parameter, r, is an exact rational number. I don't know what else to try. Thanks.

Edit: The curves I expect to get are the three black ones (marked A1, A2, and A3) on the following picture

Expected curves (the black ones)

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

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

发布评论

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

评论(5

紫罗兰の梦幻 2024-12-06 17:15:10

您确定a 的图片和/或定义吗?根据 a 的定义可知,k==w 上的 a[k,w]==0 但该曲线并未出现在你的照片中。

无论如何,假设 a 的定义是正确的,绘制等值线的问题是在域 w^2/r^2-k^2<0 中, p[k,w]Sin[p[k,w]] 都变成纯虚数,这意味着 a[k,w]也变得纯粹是想象的。由于 ContourPlot 不喜欢复值函数,因此仅绘制域 w^2/r^2>=k^2 中的等高线部分。

并不是说 Sin[p[k,w]]/p[k,w] 对于所有 kw 值都是实数(并且它在限制 p[k,w]->0) 中表现良好。因此,为了解决 a 变得复杂的问题,您可以绘制轮廓 a[k,w]/p[k,w]==0 来代替:

ContourPlot[a[k, w]/p[k, w] == 0, {w, 0, 6}, {k, 0, 14}]

结果

a/p==0 的等高线图

Are you sure about the picture and/or the definition for a? From the definition of a it follows that a[k,w]==0 on k==w but that curve doesn't appear in your picture.

Anyway, assuming that the definition of a is right, the problem with plotting the contours is that in the domain w^2/r^2-k^2<0, both p[k,w] and Sin[p[k,w]] become purely imaginary which means that a[k,w] becomes purely imaginary as well. Since ContourPlot doesn't like complex valued functions only the parts of the contours in the domain w^2/r^2>=k^2 are plotted.

Not that Sin[p[k,w]]/p[k,w] is real for all values of k and w (and it's nicely behaved in the limit p[k,w]->0). Therefore, to get around the problem of a becoming complex you could plot the contours a[k,w]/p[k,w]==0 instead:

ContourPlot[a[k, w]/p[k, w] == 0, {w, 0, 6}, {k, 0, 14}]

Result

contour plot of a/p==0

错爱 2024-12-06 17:15:10

通过单独绘制方程 lhs 的实部和虚部,我得到了与您期望的非常相似的结果:

ContourPlot[{Re@a[k, w] == 0, Im@a[k, w] == 0}, {w, 0, 6}, {k, 0, 14},
  MaxRecursion -> 7]

I have got something very similar to what you expect by separate plotting of real and imaginary parts of the l.h.s. of the equation:

ContourPlot[{Re@a[k, w] == 0, Im@a[k, w] == 0}, {w, 0, 6}, {k, 0, 14},
  MaxRecursion -> 7]

enter image description here

灰色世界里的红玫瑰 2024-12-06 17:15:10

您的函数在您显示的轮廓线区域中给出复数。这是你所期望的吗?您可以在这里看到真实的区域:

ContourPlot[a[k, w], {w, 0, 6}, {k, 0, 14}]

在此处输入图像描述

如果我在某些方面得到一些更接近您的线条的东西使用:

ContourPlot[a[w, k] == 0, {w, 0, 6}, {k, 0, 14}]

在此处输入图像描述

是否可能存在转录错误?

(如果这没有帮助,我深表歉意。)

Your function gives complex numbers in the region of the contour lines you show. Is that what you expect? You can see the region that is real here:

ContourPlot[a[k, w], {w, 0, 6}, {k, 0, 14}]

enter image description here

I get something in some ways closer to your lines if I use:

ContourPlot[a[w, k] == 0, {w, 0, 6}, {k, 0, 14}]

enter image description here

Is it possible there is a transcription error?

(My apologies if this is unhelpful.)

若水微香 2024-12-06 17:15:10

仅当 w^2 - k^2w^2/r^2 - k 时,pq 才是实值^2 都是非负的。 w^2 / r^2 - k^2 仅在绘图区域的以下区域中为非负数:

在此处输入图像描述

因此,其他所有内容都将被 ContourPlot 截断。也许您需要对方程进行一些修正(您只需要实部?幅度?)我不相信 Mathematica 给您的曲线非常不准确。否则,如果增加 PlotPointsMaxRecursion(例如,增加到 50 和 4),则可以提高轮廓的准确性。

p ans q will be real valued only if w^2 - k^2 and w^2/r^2 - k^2 are both nonnegative. w^2 / r^2 - k^2 will only be nonnegative in the following area of your plot region:

enter image description here

Therefore everything else will be cut off by ContourPlot. Perhaps you need to make some corrections to the equations (you only need the real part? magnitude?) I don't believe the curves Mathematica gives you are very inaccurate. Otherwise the way to go to increase accuracy of the contours if increasing PlotPoints and MaxRecursion (say, to 50 and 4).

娇纵 2024-12-06 17:15:10

尝试使用方程的参数化。例如,定义 a=w^2-k^2b=w^2/r^2-k^2,然后求解 a< /code> 和 b 并将它们映射到 kw

Try to play with the parametrization of your equations. For example, define a=w^2-k^2 and b=w^2/r^2-k^2, then solve for a and b and map them onto k and w

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