【问题标题】:How to proof with Sympy that a given Cartesian equation can be written as a given polar equation如何用 Sympy 证明给定的笛卡尔方程可以写成给定的极坐标方程
【发布时间】:2020-12-14 18:59:56
【问题描述】:

我有一个关于 sympy 的作业,并且正在努力解决以下问题:

"在 Sympy 的帮助下证明 4*(x2 + y2 -ax)3 = 27a 2(x2+y2)2 可以写成 r = 4a*cos (theta/3)3".

我已尝试替换 x = r*cos(theta)y = r*sin(theta)

然后我尝试了sp.solveset(eq, r),但我只得到了很长的 {},与给定的极坐标方程完全不同。

有谁知道怎么做(我可以使用 sympy 和 numpy)?

【问题讨论】:

    标签: python sympy polar-coordinates cartesian-coordinates


    【解决方案1】:

    以下代码从左侧和右侧构建方程。然后使用substitution 执行change of variables to polar coordinates

    然后将生成的三角表达式简化,简化后结果为零。所以任何对/元组(x,y)=(r*cos(theta),r*sin(theta)) 都是一个解决方案。

    from sympy import *
    a,x,y,theta = symbols('a x y \Theta', real=True)
    init_printing(use_latex=True)
    
    lhs = 4 * (x**2 + y**2 - a*x) ** 3
    rhs = 27 * a**2 * (x**2 + y**2)**2
    f = lhs - rhs
    
    r = 4 * a * cos(theta/3)**3
    display(f,"----")
    f = f.subs(x,r*cos(theta))
    f = f.subs(y,r*sin(theta))
    display(f,"----")
    f1 = f
    display(simplify(f))
    
    
    # format for wolframalpha
    t = symbols('t')
    f1 = f1.subs(theta,t)
    import re
    f1 = re.sub("\*\*","^",str(f1))
    print("----")
    print("wolframalpha expression: solve ", str(f1)," over the reals")
    

    要仔细检查这一点,最后,wolframalpha query is also generated,确认解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-13
      • 1970-01-01
      相关资源
      最近更新 更多