在Mathematica中找到隐式函数的根

时间:2011-09-09 02:59:42

标签: function wolfram-mathematica root implicit

在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}]

然而,我希望获得绘图中的数据,而不仅仅是视觉图。 那么如何找到情节数据?

3 个答案:

答案 0 :(得分:3)

我建议您探索documentation on equation solving,尤其是SolveNSolve函数。

修改

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

复制并粘贴您需要的位。

或者,在我看来,更好地解决您的实际问题。

sol = Solve[x^3 + x*y + y^2 - 36 == 0,{x}][[1]] 

您可能需要一些选项才能获得正确的解决方案。

Table[{x/. sol,y},{y, -3 Pi, 3 Pi, 0.02}]

答案 1 :(得分:3)

我不确定我是否正确解释了您的第二个问题,但假设您需要生成的ContourPlot中的(x,y)点列表,则执行此操作的一种方法可能如下:

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

获取积分列表

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

'使用ListPlot查看'

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

enter image description here

修改

纳赛尔正确指出此问题已经解决过。 Here是基本相同问题的一个链接,Szabolcs的this answer是相关的。

关于上面给出的答案,this method可能更直接:

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

最后,我应该感谢“午餐时间游乐场。与Mathematica的乐趣:如何从情节中提取点数”,请参阅here,其中提供以上建议的两种方法(现在我经常使用)。

修改2

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

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

Paul Abbott在Mathematica Journal Vol 7,No 2,pp 108-112,1998中的一篇文章, 在间隔中查找根,提供了大量有用的信息并可用here

他指出以下内容也有效

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

和(!)

plot[[1, 1]]

我在FreshApple的评论中引用了question,其中可以找到以下方法的(略有变体):

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

以下评估为True

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

编辑3

只是或有趣......

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

给出

enter image description here

答案 2 :(得分:3)

对Verbeia答案的$ .02贡献:

请记住检查x(y)和y(x)解决方案,因为其中一个可能比另一个更干净。

在你的例子中:

enter image description here