在Python中求隐式函数的根

发布于 2024-09-07 13:32:47 字数 313 浏览 1 评论 0原文

我有一个隐式函数,例如:

f(x,y) = x**y + y**y - 3*x

我想求解网格上的根。所以 f(x,y) = 0

绘制解决方案很容易:

x = linspace(-2,2,11)
y = linspace(-2,2,11)
(X,Y) = meshgrid(x,y)

A = X**Y + Y**Y - 3*X
contour(X,Y,A,0)

这很好,我绘制了所需的曲线,但是我希望获得图中的数据,而不仅仅是视觉图。那么如何找到绘图的数据呢?

I have an implicit function, for example:

f(x,y) = x**y + y**y - 3*x

I want to solve the root on a meshgrid. So f(x,y) = 0

Drawing the solution is easy:

x = linspace(-2,2,11)
y = linspace(-2,2,11)
(X,Y) = meshgrid(x,y)

A = X**Y + Y**Y - 3*X
contour(X,Y,A,0)

This works great, I have a drawing of the curve I need, however I would like to have the data that is in the plot and not only the visual plot. So how do I find the data of the plot?

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

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

发布评论

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

评论(1

眼眸里的那抹悲凉 2024-09-14 13:32:47

您可以使用以下方法获取“[matplotlib] 图中的数据”:

cs = contour(X,Y,A,0)
data = cs.collections[0].get_paths()[1]

有多种直接计算轮廓的算法,尽管我不知道任何 numpy/scipy 版本。 Marching squares 是我一直在这里谈论的一个,尽管该算法已获得专利并且存在严格的限制关于它的使用,所以我怀疑 matplotlib 使用它。 这里有一个链接,其中包含一些关于如何进行的聊天matplotlib 计算轮廓。

You can get "the data that is in the [matplotlib] plot" using:

cs = contour(X,Y,A,0)
data = cs.collections[0].get_paths()[1]

There are a variety of algorithms for calculating the contours directly, though I don't know of any numpy/scipy versions. Marching squares is the one I always here about, although the algorithm is patented and there are severe restrictions on it's use, so I doubt matplotlib uses it. Here's a link with a bit of chat on how matplotlib calculates the contours.

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