python 绘制非线性方程

python plot non linear equation

在 python 中绘制非线性方程的最简单方法是什么。

例如:

0 = sqrt((-6 - x) ** 2 + (4 - y) ** 2) - sqrt((1 - x) ** 2 + y ** 2) - 5

我想绘制 x in [0, 10] 的方程式,看起来像一条连续曲线。

谢谢!

下面是使用 numpy+matplotlib 绘制隐式方程的简单方法:

import matplotlib.pyplot
from numpy import arange, meshgrid, sqrt

delta = 0.025
x, y = meshgrid(
    arange(0, 10, delta),
    arange(0, 10, delta)
)

matplotlib.pyplot.contour(
    x, y,
    sqrt((-6 - x) ** 2 + (4 - y) ** 2) - sqrt((1 - x) ** 2 + y ** 2) - 5,
    [0]
)
matplotlib.pyplot.show()

输出:

这种方法对于分析封闭形式非常方便,例如,半径为 3 的圆看起来像:

matplotlib.pyplot.contour(
    x, y,
    x**2+y**2-9,
    [0]
)