在Mathematica中查找隐式函数的根 [英] Find root of implicit function in Mathematica

查看:240
本文介绍了在Mathematica中查找隐式函数的根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mathematica中查找隐式函数的根

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

f(x,y)= x ^ 3 + x * y + y ^ 2 - 36



找到根,即解方程 f(x,y)= 0



绘制解决方案很简单:

ContourPlot [x ^ 3 + x * y + y ^ 2 - 36 == 0,{x,-2 Pi,2 Pi },{y,-3 Pi,3 Pi}]



然而,我想要有图中的数据,而不是只有视觉情节。
那么我该如何找到该图的数据?

解决方案

我不确定我是否正在解释第二个问题是正确的,但假设您需要生成的ContourPlot中的(x,y)点列表,则可以采用以下方法之一:

  plot = ContourPlot [
x ^ 3 + x * y + y ^ 2 - 36 == 0,{x,-2 Pi,2 Pi},{y,-3 Pi,3 Pi }]

要获取点数列表

  points =个案[Normal @ plot,x_Line:> First @ x,Infinity]; 

'看看'带ListPlot

  ListPlot [points,PlotRange  - > {{-2 Pi,2 Pi},{-3 Pi,3 Pi}}] 





编辑

Nasser正确地指出,此问题已在之前解决。 这里是一个基本相同的问题的链接和这个答案与Szabolcs相关。


至于上面给出的答案, $ b $ pre $ points2 =个案[plot,x_GraphicsComplex:> ; First @ x,Infinity]

最后,我应该承认LunchTime Playground。Mathematica的乐趣:如何从曲线中提取点,请参阅 here ,它提供了 两种方法(以及我现在常用的方法)。

编辑2

这种方法是对上述方法1的改进,这些点是作为{x,y}值列表(list-of-lists)获得的,没有任何无关的{}。

 例[正常@ plot,Line [{x__}]:> x,Infinity] 

Paul Abbott在Mathematica期刊Vol 7,No 2,pp 108 -112,1998,
在区间查找根,提供了大量有用的信息,并且可用 here



他指出以下内容也有效:

 个案[Normal @ plot,_Line,-1] [[1,1]] 

和(!)

  plot [[1,1]] 

我在问题 FreshApple可能会发现以下方法(轻微变体):

  InputForm [plot] [[1,1,1]] 

以下计算结果为 True

  plot [[1,1]] ==个案[Normal @ plot,第[{x__}]行:> x,Infinity] == 
InputForm [plot] [[1,1,1]] ==例子[Normal @ plot,_Line,-1] [[1,1]]

编辑3

..

  ListPlot @ ContourPlot [x ^ 2 + y ^ 2 == 1,{x,-1,1}, {y,-1,1}] [[1,1]] 

给出




Find root of implicit function in Mathematica

I have an implicit function, for example:

f(x,y) = x^3 + x*y + y^2 - 36

I want to find the root, ie solutions to the equation f(x,y) = 0

Drawing the solution is easy:

ContourPlot[x^3 + x*y + y^2 - 36 == 0, {x, -2 Pi, 2 Pi}, {y, -3 Pi, 3 Pi}]

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?

解决方案

I'm not sure if I am interpreting your second question properly, but assuming you require a list of (x,y) points from the generated ContourPlot, one way of doing this might be the following:

plot = ContourPlot[
  x^3 + x*y + y^2 - 36 == 0, {x, -2 Pi, 2 Pi}, {y, -3 Pi, 3 Pi}]

To obtain a list of points

points = Cases[Normal@plot, x_Line :> First@x, Infinity];

'Take a look' with ListPlot

ListPlot[points, PlotRange -> {{-2 Pi, 2 Pi}, {-3 Pi, 3 Pi}}]

giving

Edit

Nasser has correctly pointed out that this question has been addressed before. Here is one link to essentially the same question and this answer by Szabolcs is relevant.

As regards the answer given above, this method is probably more direct:

points2 = Cases[plot, x_GraphicsComplex :> First@x, Infinity]

Finally, I should acknowledge " LunchTime Playground. Fun with Mathematica: How to extract points from a plot", see here, which gives both methods suggested above (and which I now use routinely).

Edit 2

This method is an improvement on method 1 above, as the points are obtained as a list of {x,y} values (list-of-lists) without any extraneous { }.

Cases[Normal@plot, Line[{x__}] :> x, Infinity]

An article by Paul Abbott in the Mathematica Journal Vol 7, No 2, pp 108-112, 1998, Finding Roots in an Interval, gives a lot of useful information and is available here

He points out the the following also work

Cases[Normal@plot, _Line, -1][[1, 1]]

and(!)

plot[[1, 1]]

I have made reference in the comments to the question by FreshApple where a (slight variant) of the following method may be found:

InputForm[plot][[1, 1, 1]]

The following evaluates to True

plot[[1, 1]] == Cases[Normal@plot, Line[{x__}] :> x, Infinity] == 
 InputForm[plot][[1, 1, 1]] == Cases[Normal@plot, _Line, -1][[1, 1]]

Edit 3

Just or fun ...

ListPlot@ContourPlot[x^2 + y^2 == 1, {x, -1, 1}, {y, -1, 1}][[1, 1]]

gives

这篇关于在Mathematica中查找隐式函数的根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆