问题描述
(1 - y)/y^4 = x^2
from sympy import symbols,Eq,solve
x,y = symbols('x y')
equation = Eq((y-1)*y**(-4),x**2)
solution = solve(equation,y)
print(solution)
我得到了这个输出的整体图:
[Piecewise((-sqrt(-(-1/x**4)**(1/3))/2 - sqrt((-1/x**4)**(1/3) - 2/(x**2*sqrt(-(-1/x**4)**(1/3))))/2,Eq(x**(-2),0)),(-sqrt(2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) + 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))/2 - sqrt(-2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) - 2/(x**2*sqrt(2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) + 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))) - 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))/2,True)),Piecewise((-sqrt(-(-1/x**4)**(1/3))/2 + sqrt((-1/x**4)**(1/3) - 2/(x**2*sqrt(-(-1/x**4)**(1/3))))/2,(-sqrt(2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) + 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))/2 + sqrt(-2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) - 2/(x**2*sqrt(2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) + 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))) - 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))/2,Piecewise((sqrt(-(-1/x**4)**(1/3))/2 - sqrt((-1/x**4)**(1/3) + 2/(x**2*sqrt(-(-1/x**4)**(1/3))))/2,(sqrt(2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) + 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))/2 - sqrt(-2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) + 2/(x**2*sqrt(2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) + 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))) - 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))/2,Piecewise((sqrt(-(-1/x**4)**(1/3))/2 + sqrt((-1/x**4)**(1/3) + 2/(x**2*sqrt(-(-1/x**4)**(1/3))))/2,(sqrt(2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) + 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))/2 + sqrt(-2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) + 2/(x**2*sqrt(2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3) + 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))) - 2/(3*x**2*(sqrt(-1/(27*x**6) + 1/(256*x**8)) + 1/(16*x**4))**(1/3)))/2,True))]
我想在0 <= y <= 1
和0 <= x <= some_large_number
的边界上绘制它。我还无法弄清楚该怎么做,但是我敢肯定,如果我的cpu使用PITA,那对我来说一定很容易。
此外,对我而言,以解析方式解决此问题也无济于事。我会很高兴以数字方式执行此操作,但是我也不知道该怎么做。 Sympy只是向我展示的一种解决方案。
解决方法
符号似乎是mixing in complex solutions。我不确定在这种情况下如何应对。请注意,对于y
小于1的情况,LHS为负,因此永远不要等于实数的平方。
但是,如果您最感兴趣的是情节,plot_implicit
会派上用场:
from sympy import symbols,Eq
from sympy.plotting import plot_implicit
x,y = symbols('x y') # symbols('x y',real=True,positive=True) doesn't seem to make a difference
equation = Eq(((y - 1) * y ** (-4)),x ** 2)
plot_implicit(equation)
PS:要找到曲线的最右点,请对左侧solve(equation.lhs.diff())
求微分,得出解y = 4/3
,对应于x = 2*sqrt(3)/3
。寻找y >= 1
的数值解很简单。 nsolve
可以找到小于x0
的给定2*sqrt(3)/3
的数值解,例如nsolve(equation.subs(x,.1),1)
给出1.01042350456793
。