python - sympy integration with quotient and cot(x) not getting simplifed results - Stack Overflow
I am trying to use sympy to integrate 1 / (1 + cot(x)) for variable x, (or its equivalent sin(x) / (sin(x) + cos(x)) ).
I tried
from sympy import *
x = symbols("x", real=True)
integrate(sin(x) / (sin(x) + cos(x)), x)
and the results look good:
But while I'm trying
from sympy import *
x = symbols("x", real=True)
integrate(1 / (1 + cot(x)), x)
it produces
which is not wrong because I tried to manually simplify that to the results above.
as it is not simplified, I called the simplify()
function for this result, but the following is what I got:
However, that's again correct but not well simplified. My questions are:
- In such a case how am I able to get a correctly simplifed result if I try to integrate
integrate(1 / (1 + cot(x)), x)
(or any other similar functions as this type). - If 1 is impossible, how do I manually hint sympy so that it can produce a correctly simplified result for me?
I am trying to use sympy to integrate 1 / (1 + cot(x)) for variable x, (or its equivalent sin(x) / (sin(x) + cos(x)) ).
I tried
from sympy import *
x = symbols("x", real=True)
integrate(sin(x) / (sin(x) + cos(x)), x)
and the results look good:
But while I'm trying
from sympy import *
x = symbols("x", real=True)
integrate(1 / (1 + cot(x)), x)
it produces
which is not wrong because I tried to manually simplify that to the results above.
as it is not simplified, I called the simplify()
function for this result, but the following is what I got:
However, that's again correct but not well simplified. My questions are:
- In such a case how am I able to get a correctly simplifed result if I try to integrate
integrate(1 / (1 + cot(x)), x)
(or any other similar functions as this type). - If 1 is impossible, how do I manually hint sympy so that it can produce a correctly simplified result for me?
1 Answer
Reset to default 0As Oscar points out, it is easier to get to a desired form after integration by getting the expression in a desired form before you start. Otherwise, getting to that form after integration can be tedious because of assumptions that block certain simplifications:
from sympy import *
x = symbols("x", real=True)
eq=integrate(1 / (1 + cot(x)), x)
from sympy.simplify.fu import TR22
p=Symbol('p',positive=True)
s=bottom_up(eq,TR22).subs(sec(x),p).expand().subs(p,sec(x))
s=logcombine(2*(s-x/2),force=True)/2+x/2 # seems like logcombine could gather better on its own
s=bottom_up(_,fu)
s=expand_trig(s)
s=factor_terms(s)
s=expand_log(s,force=True)
>>> s
(x - log(sin(x) + cos(x)))/2
- .NET开源:微软"云为先"战略的全面铺开
- 英特尔CEO欧德宁:笔记本与平板电脑终将融合
- 80后回忆录 那些年我们折腾过的IT玩意
- Pre-increment and Post-increment in C - Stack Overflow
- visual studio 2017 - C++ build errors with wxWidgets 3.1.2 and Connect method - Stack Overflow
- react native - Handling loginlogout without user undefined errors - Stack Overflow
- IMDB pagination-container for a series in python - Stack Overflow
- gdal - Using gdal_translate to compress multiple TIFF files - Stack Overflow
- c++ - Changing STL container (std::string) values in debugger - Stack Overflow
- node.js - Test backend functionality nodespostman error - Stack Overflow
- starknet - How to generate and verify a STARK proof from a Cairo program locally? - Stack Overflow
- python - How can I use FilteredSelectMultiple widget in a django custom form? - Stack Overflow
- node.js - Cookies Blocked in Cross-Origin Requests Between Netlify Frontend(Reactjs) and Railway Backend (Node ts) - Stack Overf
- reactjs - How to deploy Laravel (with react) app on heroku without any error (like 419 error) - Stack Overflow
- vim - Neovim - How to select autocomplete option in :e command without opening it? - Stack Overflow
- ZeroMQ Subscriber in Rails Worker Fails to Receive Messages, but Works with QLStats - Stack Overflow
- javascript - How can I create hyperlinkOrPicture column types on SharePoint Lists with Microsoft Graph API or Sharepoint API? -
integrate((1/(1+cot(x))).rewrite('sincos'), x)
. – Oscar Benjamin Commented yesterday