如何用 Sympy 证明给定的笛卡尔方程可以写成给定的极坐标方程 [英] How to proof with Sympy that a given Cartesian equation can be written as a given polar equation

查看:37
本文介绍了如何用 Sympy 证明给定的笛卡尔方程可以写成给定的极坐标方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 sympy 的作业,正在为以下问题而苦苦挣扎:

<块引用>

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

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

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

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

解决方案

以下代码从左手边和右手边构建等式.然后

i have an assignment on sympy and am struggling with the following question:

"Prove with the help of Sympy that 4*(x2 + y2 -ax)3 = 27a2(x2+y2)2 can be written using r = 4a*cos(theta/3)3".

I have tried to substitute x = r*cos(theta) and y = r*sin(theta).

Then I tried sp.solveset(eq, r) but I only got a very longset of {}, nothing like the given polar equation.

Does anyone know how to do this (I can use sympy and numpy)?

解决方案

The following code builds the equation from its left hand side and right hand side. Then the change of change of variables to polar coordinates is performed using substitution.

The resulting trigonometric expression is then simplified, and it turns out to be zero after simplification. So any pair/tuple (x,y)=(r*cos(theta),r*sin(theta)) is a solution.

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")

To double-check this, at the end, a wolframalpha query is also generated, which confirms the solutions.

这篇关于如何用 Sympy 证明给定的笛卡尔方程可以写成给定的极坐标方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆