本文介绍了绘制隐函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 R 中绘制以下隐式公式:

I'm trying to plot the following implicit formula in R:

1 = x^2 + 4*(y^2) + x*y

1 = x^2 + 4*(y^2) + x*y

这应该是一个椭圆.我想随机采样 x 值,然后根据这些值生成图表.

which should be an ellipse. I'd like to randomly sample the x values and then generate the graph based on those.

这是一个相关的线程,但那里的解决方案似乎是特定的到 3D 案例.这个问题比我预期的更能抵抗谷歌搜索,所以也许 R 语言将隐式公式称为其他东西.

Here's a related thread, but the solutions there seem to be specific to the 3D case. This question has been more resistant to Googling that I would have expected, so maybe the R language calls implicit formulas something else.

提前致谢!

推荐答案

你可能不明白的两件事.使用该技术绘制隐函数时,您需要将所有项移动到函数的 RHS,以便您的隐函数变为:

Two things you may not understand. When plotting implicit functions with that technique, you need to move all terms to the RHS of the function so that your implicit function becomes:

0 = -1+ x^2 + 4*(y^2) + x*y

然后使用零的轮廓值是有意义的:

Then using the contour value of zero will make sense:

x<-seq(-1.1,1.1,length=1000)
y<-seq(-1,1,length=1000)
z<-outer(x,y,function(x,y) 4*y^2+x^2+x*y -1 )
contour(x,y,z,levels=0)

我在第一个版本上有一个错误.@mnels' 是正确的.

I got a sign wrong on the first version. @mnels' was correct.

这篇关于绘制隐函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 13:14