如何在 Sympy 中将 `sin(x)^2` 重写为 cos(2*x) 形式 [英] How to rewrite `sin(x)^2` to cos(2*x) form in Sympy

查看:36
本文介绍了如何在 Sympy 中将 `sin(x)^2` 重写为 cos(2*x) 形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Mathematica 等其他 CAS 中很容易获得这种重写.

It is easy to obtain such rewrite in other CAS like Mathematica.

TrigReduce[Sin[x]^2]

(*1/2 (1 - Cos[2 x])*)

然而,在 Sympy 中,trigsimp 与所有测试的方法返回 sin(x)**2

However, in Sympy, trigsimp with all methods tested returns sin(x)**2

trigsimp(sin(x)*sin(x),method='fu')

推荐答案

完整的福"方法尝试许多不同的变换组合来找到最好的".结果.

The full "fu" method tries many different combinations of transformations to find "the best" result.

Fu 例程中使用的各个变换可以是用于进行有针对性的转换.您将不得不阅读文档以了解不同功能的作用,但只需运行 FU 字典的功能即可在此处将 TR8 识别为您的主力:

The individual transforms used in the Fu-routines can be used to do targeted transformations. You will have to read the documentation to learn what the different functions do, but just running through the functions of the FU dictionary identifies TR8 as your workhorse here:

    >>> for f in FU.keys():
    ...   print("{}: {}".format(f, FU[f](sin(var('x'))**2)))
    ...
8<---
    TR8 -cos(2*x)/2 + 1/2
    TR1 sin(x)**2
8<---

这篇关于如何在 Sympy 中将 `sin(x)^2` 重写为 cos(2*x) 形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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