Sympy:用平方和根化简小复合分数 [英] Sympy: Simplify small compound fraction with squares and roots

查看:32
本文介绍了Sympy:用平方和根化简小复合分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下情况(在 Sympy 1.8 中):

I have got the following situation (in Sympy 1.8):

from sympy import *
u = symbols('u') # not necessarily positive
term = sqrt(1/u**2)/sqrt(u**2)

该术语呈现为

如何将其简化为 1/u**2,即 ?

How can I simplify this to 1/u**2, i.e. ?

我尝试了 https://docs.sympy.org/latest 中的许多功能/tutorial/simplification.html,以及 https 中列出的一些参数://docs.sympy.org/latest/modules/simplify/simplify.html 但无法让它工作.

I have tried many functions from https://docs.sympy.org/latest/tutorial/simplification.html, and some arguments listed in https://docs.sympy.org/latest/modules/simplify/simplify.html but could not get it to work.

推荐答案

变量需要声明为实数:

u=symbols('u', real=True)

然后该术语会自动简化.

Then the term is auto-simplified.

(我建议进行相应的Sympy 文档更改.)

(I suggested a corresponding Sympy documentation change.)

这篇关于Sympy:用平方和根化简小复合分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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